簡體   English   中英

匯編中添加大小不同的數字

[英]Addition of different sized numbers in assembley

我被要求寫一個程序來添加一個字節大小的數組元素。 前2個字節是數組中元素的數量。

該數組可能包含數千個數字,因此我應該將總和放入32位寄存器(例如ax:dx )中,但問題是我不知道如何從內存中取出一個字節,然后將其添加到32位寄存器中(或內存中的double變量)。

我嘗試在內存中使用16位寄存器和word變量進行添加。 這是代碼:

array db 07, 00, 30, 10, 77, 14, 9, 54, 100
sum dw ?


lea ax, data
mov ds, ax
mov es, ax

lea bx, array
mov cx, [bx] 
mov bx, 0002h
mov dx, 0000h
Addition:
mov dl, [bx]
mov dh, 00h
add sum, dx
add bx, 1
loop Addition 

mov ax, 4c00h
int 21h 

它可以正常工作。 但是我想知道如何使用32位寄存器和一個double變量來執行此操作。

我用emu8086

要將BL的8位值添加到DX:AX的32位總和中:

xor bh,bh  ; Clear BH (effectively zero-extends BL into BX)
add ax,bx  ; Add BX to the lower half of the sum
adc dx,0   ; If the lower half wrapped around (the above addition resulted
           ; in a carry), add 1 to the upper half, otherwise add 0.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM