All About Circuits Forum 8086, hex to decimal program , converting prob
 Register Blogs FAQ Members List Today's Posts Search Today's Posts Mark Forums Read

 Homework Help Stuck on a textbook question or coursework? Cramming for a test and need help understanding something? Post your questions and attempts here and let others help.

#1
03-31-2009, 09:06 PM
 fortune2k Junior Member Join Date: Mar 2009 Posts: 19
8086, hex to decimal program , converting prob

Hi im trying to make a program to the following specifications:

0) initialise a temporary numerical value to 00H, base value to 10H and count value to 00H
2) Apply series of checks against ‘0’-‘9’ and ‘A’-‘F’ and convert the digit to a numerical value as described above
3) multiply our temporary numerical value by the base (10H) – remember that mul multiplies the src with what is in AL or AX so we need to make sure that the temporary numerical value is moved into AX before we multiply and since AL contains our digit numerical value we will need to push AX to save it for use later - use version b) of mul i.e. src is 16 bit, result in high word in DX (we will discard this) and low word in AX (which we will use). We can safely multiply by the base the first time round as the temporary numerical value will start out as initilised to 0.
5) pop AX so we can get the new numerical digit value and add it to the temporary numerical value
6) increment count of digits converted and go back to 1)

Note – you will also need to echo the digit characters input, but you should ignore i.e. not echo, the non-hex digit termination character.

Using the above write the code to input a hex number of up to a word in size as a subroutine called GetHex in Stdio.asm.
The return numerical value should be in DX and the count of the number of digits converted should be in CX.

You can use the subroutine Getch to read the characters. You should echo the character typed in using Putch, but since Putch expects the character to be output in DL, you may need to save DX onto the stack before using Putch and pop DX after using Putch. Do not echo the termination character – simply discard it.

You can check this works by calling GetHex from your main code and then checking the result using debug.

and well my problem is that im finding it hard to convert the number to hex. I have got the read character , echo character and the if statements to ensure that the character is a hex number valid.

Code:
MOV BL, 10h ; sets the base value to 10h

Number:
sub al, 30h
mov ch,al

Letter:
sub al, 31h
mul,BL ; bl*AL  so 16*al

Continue:
inc cx ; CX counts the amount of converted
Select All
the code above atm gets the decimal value for instance if the character 'A' has been input it would get to the Letter label and then have 31h taking from it (41-31=10) so it converts the character to decimal. if '1' is input it goes to the number label and takes 30h from it (31h-30=1). what i am stuck with is then converting the decimal values back into hex because im meant to allow up to 4 hex characters to be input soo i could have '1F2A' how could i convert that to hexadecimal because i know you use powers and stuff to convert dec to hex.. I have been trying for about 5 hours to get this to work i just cant get my head around it . can you guys help me please

thanks soo much
#2
03-31-2009, 11:55 PM
 thatoneguy Senior Member Join Date: Feb 2009 Location: Midwest USA Posts: 6,356 Blog Entries: 4

You should mention "PC" in the title, since you have all the BIOS Interrupt functions to work with.

Doing this without the BIOS would be... interesting..

P.S. Why didn't you just ask this right away instead of the 0-9 check?
#3
04-01-2009, 01:13 AM
 fortune2k Junior Member Join Date: Mar 2009 Posts: 19

i check if its 0-9 because then i can convert

im just stuck on this part

multiply our temporary numerical value by the base (10H) – remember that mul multiplies the src with what is in AL or AX so we need to make sure that the temporary numerical value is moved into AX before we multiply and since AL contains our digit numerical value we will need to push AX to save it for use later - use version b) of mul i.e. src is 16 bit, result in high word in DX (we will discard this) and low word in AX (which we will use). We can safely multiply by the base the first time round as the temporary numerical value will start out as initilised to 0.

i have no idea how i would do that . anyone have any ideas?
#4
04-01-2009, 06:37 AM
 thatoneguy Senior Member Join Date: Feb 2009 Location: Midwest USA Posts: 6,356 Blog Entries: 4

Do shift operations for each hex digit?

AND 0x000F
x 10
if overflow, add to next digit,
repeat....

 Tags 8086, converting, decimal, hex, prob, program

 Related Site Pages Section Title Worksheet Numeration systems Textbook Conversion from decimal numeration : Numeration Systems Textbook Octal and hexadecimal to decimal conversion : Numeration Systems

 Similar Threads Thread Thread Starter Forum Replies Last Post nyasha Homework Help 2 03-31-2009 04:59 AM nuttertools Embedded Systems and Microcontrollers 6 12-21-2008 08:07 AM majoritical Embedded Systems and Microcontrollers 1 05-02-2008 07:41 PM ramesh_manu Programmer's Corner 4 01-18-2008 11:06 AM Reshma Programmer's Corner 6 12-19-2007 01:16 PM

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Electronics Forums     General Electronics Chat     The Projects Forum     Homework Help     Electronics Resources Software, Microcomputing, and Communications Forums     Programmer's Corner     Embedded Systems and Microcontrollers     Computing and Networks     Radio and Communications Circuits and Projects     The Completed Projects Collection Abstract Forums     Math     Physics     General Science All About Circuits Commmunity Forums     Off-Topic     The Flea Market     Feedback and Suggestions

All times are GMT. The time now is 11:16 PM.