在emu8086中添加两个总和大于255的数字?

时间:2017-11-03 22:54:34

标签: assembly emu8086

你好,我需要你的帮助来修改我的代码,所以你可以帮我解决以下问题 任务说 写下数组的前15个字 1,6,6,11,16,26,(每个下一个数字比前两个数字的总和小1例如:16 = 6 + 11 - 1,11 = 6 + 6-1,依此类推等下一个数字是16 + 26-1 = 41 ......)

我的代码运行良好,但不会写入大于255的数组,(当两个数字的总和-1大于255时)我如何解决这个问题? 更加清晰,你可以在这张照片上看到结果https://ibb.co/g6gNsb 所以 26 + 41 = 67 - 1 = 66 这个数字是okey但是当 106 + 171 = 277(数字大于255)时,下一个数字是20错误下一个数字应该是276,所以一个等等

这是我的答案:

data segment

array dw 1,6,6,11,16,26,?,?,?,?,?,?,?,?,?,?
numberBefore dw 0
numberNow dw 0

ends                     

stack segment
    dw   128  dup(0)          
ends                   


code segment           

start:
; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax

; add your code here

    mov si,09d      ;to start from 26 
    mov cx,9d
    listing:
    mov dx,array[si]
    mov numberNow,dx

    sub si,2d       ;sub to to get the number before
    mov dx,array[si]
    mov numberBefore,dx

    mov ax,numberBefore
    add ax,numberNow
    sub ah,0001h    
    add si,4d      ;add 4 to get to the next slot
    ;the next number that needs to be in array
    mov array[si],ax


    loop listing


finish:
endp 

end start 

它可以工作,直到需要将大于255的数字放入数组中。 非常感谢你

0 个答案:

没有答案