访问数组的索引

时间:2014-02-08 03:59:58

标签: assembly masm

我是汇编语言的新手,我的课程基于MASM。我的目标是从用户输入中获取数组的索引。

.data
myDates BYTE 1,2,3,4,5,6,7,8,9,10,11,12

.code
main PROC

Month:
mov edi, ecx                ; edi = ecx copy counter 

mov edx, OFFSET disMonth        ; edx = disMonth
call WriteString            ; write ax
call ReadInt                ; eax = user input

cmp eax, 12             ; no, is eax > 12
JA  ErrorMonth              ; yes, jmp to ErrorMonth
cmp eax, 0              ; no, is eax > 0
JA CalMonth             ; yes, jmp to CalMonth

ErrorMonth:
mov edx, OFFSET errMsg              ; edx = errMsg
call WriteString            ; display edx
jmp Month               ; jmp back to Month

CalMonth:
                    ; calculating (m + 9) % 12
add eax, 9              ; eax += 9
mov edx, 0              ; edx = 0
mov ecx, 12             ; ecx = 12
div ecx                 ; eax = Q & edx = R

mov ebx, edx                ; ebx = edx *Month Storage*



Day:
mov edx, OFFSET disDay              ; edx = disDay
call WriteString            ; write edx
call ReadInt                ; eax = user input

mov ebp, eax                ; ebp = eax *Day Storage*

movzx eax, monthDate[ebx - 1]
call WriteInt

cmp ebp, eax                ; is ebp > eax
JA ErrorDay             ; jmp to ErrorDay
jmp Year                ; jmp to Year

如果ebx == 12由于某种原因输出为9而不是12.但是当我用11替换ebx - 1时,它会按照它应该打印12。有什么我想念的吗?

1 个答案:

答案 0 :(得分:-2)

Nathan said in their last comment

  

这是因为我使用的是CalMonth之后的答案,所以它是9。