0

我有一个汇编 x86 问题

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

谁能帮忙?预先感谢

4

2 回答 2

0

你所追求的答案,10decimal 将出现在 edx 和 eax 将是 0

移动 ebx, 0

移动斧头,14

子斧头,月

mov bx, 12

div bx

10/12 = eax 中的 0 和 edx 中的 10 余数

于 2013-05-03T10:11:36.103 回答
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
于 2013-05-06T16:58:38.070 回答