首先,這是作業。將十進制轉換爲十六進制
我想讀取一個5位數字進入寄存器bx。該數字被假定爲不大於65535(16位)。以下是我如何嘗試這樣做。
但是,當我嘗試打印該號碼時,我只打印輸入的最後一位數字。這導致我猜測,當我向bx添加另一個數字時,它將覆蓋以前的數字,但我無法看到問題。任何幫助,將不勝感激,我幾乎可以肯定,這是小東西我俯瞰: -/
mov cx,0x05 ; loop 5 times
mov bx,0 ; clear the register we are going to store our result in
mov dx,10 ; set our divisor to 10
read:
mov ah,0x01 ; read a character function
int 0x21 ; store the character in al
sub al,0x30 ; convert ascii number to its decimal equivalent
and ax,0x000F ; set higher bits of ax to 0, so we are left with the decimal
push ax ; store the number on the stack, this is the single digit that was typed
; at this point we have read the char, converted it to decimal, and pushed it onto the stack
mov ax,bx ; move our total into ax
mul dx ; multiply our total by 10, to shift it right 1
pop bx ; pop our single digit into bx
add bx,ax ; add our total to bx
loop read ; read another char
如果你將十進制轉換爲十六進制,那麼怎麼樣,你除以10呢?當convertng爲十六進制時,你不需要乘以/除以10 – fazo 2011-04-03 23:09:48
我沒有看到我在哪裏在我發佈的片段中除以10。但是我乘以10的原因是因爲我一次只能讀取1 *字符*,並且我需要將它乘以10,這樣當我添加另一個數字時,它就在適當的位置。 – Adam 2011-04-03 23:16:50
+1用於發佈作業問題並顯示您已經嘗試過的內容。 – vcsjones 2011-04-03 23:18:10