I currently got an assignment where I have to code in assembly language where you take user input to get a 4 digit hexadecimal value and convert it into binary and then after you get the binary value you have to convert it into a month day and year, where the first 7 digits would be the year, the next four are the month, and the last 5 are the day.
I have everything converted into binary and have an idea of how to get it from binary into normal integer values for the year, month and day. When I run my code the output is 0/0/0
. I'm not sure if it is where I messed up with my shifting or something else. Could you guys take a look and give me an input on where to correct? In the code that I'm pasting, I'm only putting up to calcYear and figured I can figure that out and then work on the rest from there.
My code:
firstLine:
call crlf
mov si, offset programOne
mov cx, programOneLen
call putStrng ;displays 'Program by Joe Remaklus'
call crlf
call crlf
call inputVal ;prompt for hex input
call putBin ;display the value in AX as binary
call crlf
call calcYear ;display the year of the first 7 binary digits.
mov si, offset slash
mov cx, slashLen
call putStrng
call calcMonth ;display the month of the next 4 binary digits.
mov si, offset slash
mov cx, slashLen
call putStrng
call calcDay ;display the day of the next 5 binary digits.
call crlf
call inputVal
call putBin
mov ah,04c
int 021
prompt db 'Enter a 4-digit hex value'
lenPrompt = $-prompt
inputVal:
push si, cx
mov si, offset prompt
mov cx, lenPrompt
call putStrng
call crlf
call getHex
call crlf
pop cx, si
ret
;---------------------------------------------------------------
putBin:
push ax, cx, dx
mov cx, 16 ;number of bits to display
putBinLoopTop:
mov dl, '0' ;assume bit to display is zero
shl ax, 1 ;shift bit to display into Carry Flag
jnc putBinSkipInc ;if the top bit was zero skip the inc
inc dl ;else inc DL to '1'
putBinSkipInc:
call putChar ;display the character in DL
loop putBinLoopTop ;continue until 16 bits are displayed
pop dx, cx, ax
ret
;---------------------------------------------------------------
calcYear:
mov year, 0
mov si, 0
shl ax, 1
adc si, 0
iMul onetwoeight
add year, si
mov si, 0
shl ax, 1
adc si, 0
iMul sixfour
add year, si
mov si, 0
shl ax, 1
adc si, 0
iMul threetwo
add year, si
mov si, 0
shl ax, 1
adc si, 0
iMul sixteen
add year, si
mov si, 0
shl ax, 1
adc si, 0
iMul eight
add year, si
mov si, 0
shl ax, 1
adc si, 0
iMul four
add year, si
mov si, 0
shl ax, 1
adc si, 0
iMul two
add year, si
mov si, 0
shl ax, 1
adc si, 0
iMul one
add year, si
mov si, year
add si, 1980
call putPos
ret