Question

i have an assembly x86 question

INCLUDE Irvine32.inc
.data
day WORD 0
month WORD 0
year WORD 0

count BYTE 0

prompt1 BYTE "enter month: ",0
prompt2 BYTE "enter day: ",0
prompt3 BYTE "enter an year: ",0
prompt4 BYTE " the day of the week is ",0
.code
main PROC

mov edx, OFFSET prompt1
call writeString
mov edx, 0
mov eax, OFFSET month
mov ecx, 19
call readInt
call crlf
mov eax, 0
mov ecx, 0

mov edx, OFFSET prompt2
call writeString
mov edx, 0
mov eax, OFFSET day
mov ecx, 19
call readInt
call crlf
mov eax, 0
mov ecx, 0

mov edx, OFFSET prompt3
call writeString
mov edx, 0
mov eax, OFFSET year
mov ecx, 19
call readInt
call crlf
mov eax, 0
mov ecx, 0

mov ebx, 0
mov ax, 14
sub ax, month
mov bx, 12
div bx
mov ebx, 0
sub year, ax
mov ecx, 0
mov cx, year


    exit
main ENDP

END main

so i have to do 2 arithmetic equation for this code

a = (14 - month) / 12
y = year - a

this is my input

enter month: 4

enter day: 15

enter an year: 2013

I'm expecting the value of y after the last instruction to be 7dd(2013)

but i got value of register ecx is 0000FFFF, why isn't the value of y 7dd, but FFFF

can anyone help? thank in advance

Was it helpful?

Solution 2

INCLUDE Irvine32.inc
.data
day WORD 0
month WORD 0
year WORD 0


prompt1 BYTE "enter month: ",0
prompt2 BYTE "enter day: ",0
prompt3 BYTE "enter an year: ",0
prompt4 BYTE " the day of the week is ",0

.code
main PROC

mov edx, OFFSET prompt1
call writeString
mov edx, 0
call readInt
call crlf
mov month, ax

mov eax, 0
mov edx, OFFSET prompt2
call writeString
mov edx, 0
call readInt
call crlf
mov day, ax


mov eax, 0
mov edx, OFFSET prompt3
call writeString
mov edx, 0
call readInt
call crlf
mov year, ax



mov eax, 0
mov ebx, 0
mov ax, 14
sub ax, month
mov bx, 12
div bx
mov si, ax ;; a store in si
sub year, ax
mov di, year ;; y store in di
mov ax, ax
mul bx
add ax, month
mov cx, 2
sub ax, cx
mov ecx, 0
mov cx, ax ;; m store in cx

mov eax, 0
mov ebx, 0
mov esp, 0
mov ebp, 0

add day, di
mov ax, di
mov bx, 4
div bx
add day, ax
mov eax, 0
mov ebx, 0
mov ax, di
mov bl, 100
div bl
mov ah, 0
sub day, ax


mov eax, 0
mov ebx, 0
mov dx, 0
mov ax, di
mov bx, 400
div bx
add day, ax
mov bp, day  ;; temporary holder for d value up to y/400 calculation

mov eax, 0
mov ebx, 0
mov ax, 31
mul cx
mov bx, 12
div bx
add bp, ax
mov al, 7
div al




    exit
main ENDP

END main

OTHER TIPS

The answer you are after, 10decimal will appear in edx and eax will be 0

mov ebx, 0

mov ax, 14

sub ax, month

mov bx, 12

div bx

10/12 = 0 in eax and the 10 remainder in edx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top