2013-05-03 63 views
0

我有一個組件86問題計算組件86的算術表達式

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 

所以我必須做2運算式爲這個編碼

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

這是我的輸入

enter month: 4 

enter day: 15 

enter an year: 2013 

我期待在最後一條指令之後y的值是7dd(2013)

但我得到的寄存器ecx的值是0000FFFF,爲什麼不是y 7dd的值,但FFFF

任何人都可以幫忙嗎? 預先感謝

+0

仔細看一下分割的結果。 – 2013-05-03 04:46:48

回答

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

你之後的答案,10decimal將出現在EDX和EAX爲0

MOV EBX,0

MOV AX,14

子斧子,一個月

MOV BX,12

DIV BX

10/12 = 0在eax中,edx中的10個餘數