problem
Find the sum of all odd numbers within 100 and store it in the word variable X.
Code
data segment
x dw ?
data ends
stack segment stack
db 100 dup(?)
stack ends
code segment
assume cs:code,ds:data,ss:stack
main proc far
start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov ax,100
mov x,ax
mov bx,0 ;用bx来保存和
mov ax,1 ;用ax表示每个奇数
mov cx,0
L1:
add bx,ax
add ax,2
cmp ax,x
jbe L1
mov x,ax
mov ax,4c00h
int 21h
main endp
code ends
end start
operation result
Note: The display in debug is hexadecimal. You can see that it is 09c4 in bx to
convert to decimal.
Hand calculation is impossible. It is impossible to calculate by hand in this life, hahahahaha