NASM部门给了我错误的结果

时间:2014-10-26 20:33:02

标签: linux nasm division

好吧,所以我应该创建一个程序来确定NASM上任何给定日期的日期,我很确定我知道该怎么做。然而,这是我第一次使用NASM,而且我对一些东西一无所知。例如,我相信我的这个分区的问题与我正在分配的内存有关,如果我将其更改为其他东西它总是给我一个浮点错误。我也不太确定我对分裂的了解非常好。

这是我的代码:

;Dates and leap years 

%include "/home/usr/Desktop/io.mac"



.DATA 
day_msg db 'Enter the day(number from 1-31): ',0        ;prompt messages for the user, asks for day, month and year
month_msg db 'Enter the month(number from 1-12): ',0
year_msg db 'Enter the year: ',0
result_msg db 'The result is:',0
;----------------------------------------------------------------------------
.UDATA
day resb 1          ;memory reservations for day, month, year and the result of the operation
month resb 1        ;the output of the user is stored in these spaces, also kept around if they are required after the operation
year resd 1
result resb 1
temp resb 1
;-------------------------------------------------------------------------------------
.CODE 
    .STARTUP 
    ;asks user for day
    PutStr day_msg
    GetInt [day]

    ;asks user for month
    PutStr month_msg
    GetInt [month]  

    ;asks user for year
    PutStr year_msg
    GetInt [year]

    ;this performs the mathematical operation to figure out the day
    mov AX,[year]       ;saves AX with the year value 
    mov CX, 4       ;sets CX to 4
    div CX          ;divides AX by CX, which is 4
    mov [temp],AL   ;extracts result from division by 4 

    PutStr result_msg
    PutInt [temp]
    nwln 
    .EXIT

它还没有做任何事情,因为我被困在其中一个部门。例如,如果我指定年份是1969年,它会抛出236作为答案,这将在接下来的步骤中给我一个错误的读数。它应该给我492而不是。我不明白为什么我得到那个答案。

0 个答案:

没有答案
相关问题