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.
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
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