All About Circuits Forum  

Go Back   All About Circuits Forum > Electronics Forums > Homework Help

Notices

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.

Reply   Post New Thread
 
Thread Tools Display Modes
  #1  
Old 03-31-2009, 09:06 PM
fortune2k fortune2k is offline
Junior Member
 
Join Date: Mar 2009
Posts: 19
Default 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
1) Read in a character
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                
        JGE Continue ;jump to Continue , if true
        
    Letter: 
        sub al, 31h
        mul,BL ; bl*AL  so 16*al
        JGE Continue ;jump to Continue , if true    

    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
Reply With Quote
  #2  
Old 03-31-2009, 11:55 PM
thatoneguy's Avatar
thatoneguy thatoneguy is offline
Senior Member
 
Join Date: Feb 2009
Location: Midwest USA
Posts: 6,356
Blog Entries: 4
Default

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?
Reply With Quote
  #3  
Old 04-01-2009, 01:13 AM
fortune2k fortune2k is offline
Junior Member
 
Join Date: Mar 2009
Posts: 19
Default

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?
Reply With Quote
  #4  
Old 04-01-2009, 06:37 AM
thatoneguy's Avatar
thatoneguy thatoneguy is offline
Senior Member
 
Join Date: Feb 2009
Location: Midwest USA
Posts: 6,356
Blog Entries: 4
Default

Do shift operations for each hex digit?

AND 0x000F
x 10
if overflow, add to next digit,
repeat....
Reply With Quote
Reply   Post New Thread

Tags
, , , , ,


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
Converting from decimal number to base 3 number system nyasha Homework Help 2 03-31-2009 04:59 AM
converting hex file to asm file nuttertools Embedded Systems and Microcontrollers 6 12-21-2008 08:07 AM
converting Keil assembly file to hex file majoritical Embedded Systems and Microcontrollers 1 05-02-2008 07:41 PM
Interacting with C program (8086 + C) ramesh_manu Programmer's Corner 4 01-18-2008 11:06 AM
8086 Microprocessor using Debug (hex to bin conversion) Reshma Programmer's Corner 6 12-19-2007 01:16 PM

Thread Tools
Display Modes

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 Jump


All times are GMT. The time now is 03:03 AM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.