0
我正在編寫一個簡單的sprintf()函數。當我嘗試除以$ 0xA時,我似乎無法找出爲什麼我的代碼得到一個算術豁免。如果我將所有內容都更改爲擴展版本(如%EAX),則不會發生這種情況。爲什麼使用divw時會出現算術異常?
.data
divisor: .byte 0xA
.text
.globl sprinter
sprinter:
.
.
.
add_unsigned_decimal_number:
pushl (%ebx)
call uint_inner
jmp next_char
uint_inner:
xor %eax, %eax
xor %edx, %edx
movw 4(%esp), %dx #Move first half of the parameter into %dx
movw 6(%esp), %ax #Move second half into %ax
#################Here it crashes###################
divw divisor #Divide by 10 (0xA)
###################################################
cmpw $0x0, %ax
je return #return if equal
pushw %dx #Save the result
pushw %ax #add a parameter for the next call
call uint_inner
pop %eax #to remove the top layer
pop %eax #To extract the required layer
addb $48, %al #To make it into a number symbol
movb %al, (%ebx) #Add the number
ret
非常感謝您的幫助。 請記住,這是一個學校問題,所以試圖解釋,而不只是給工作代碼。
我明白了。我認爲它會被忽略。感謝您的解釋清楚。最後一個問題,爲什麼我應該使用.short而不是.byte? – NoobsDeSroobs
因爲'divw'使用16位除數和'.byte'只定義了它的8位,所以沒有告訴什麼前8位都將是。 – Jester