"Assembly Language" - Reading Notes - Experiment 4 [bx] and the use of loop
- Programming,
0:200~0:23F
sequentially transfer data to memory0~63
(3FH). - Programming,
0:200~0:23F
transfer data to the memory sequentially0~63
(3FH), only 9 instructions can be used in the program, and the 9 instructions includemov ax, 4c00h
andint 21h
assume cs:code
code segment
mov ax, 20h ;配合bx正好得到 20h*16 + 0 =0200h
mov ds, ax ;设置(ds)=0
mov bx, 0
mov cx, 64 ;设置循环次数(0时结束,所以要多给一次)
s: mov [bx], bx ;0 送到 200 遍历63次,每次bx+1
inc bx ;偏移地址向前移动
loop s ;检测循环条件,符合就循环,否则向下继续
mov ax, 4c00h
int 21h
code ends
end
- The function of the following program is to
mov ax,4c0h
copy the previous instruction to the memory0:200 处
and complete the program. Debug on the machine and track the running results.
assume cs:code
code segment
mov ax, cs ;配合bx正好得到 20h*16 + 0 =0200h
mov ds, ax ;设置(ds)=0
mov ax, 0020h
mov es, ax
mov bx, 0
mov cx, cx ;设置循环次数(0时结束,所以要多给一次)
s: mov al, [bx] ;
mov es:[bx], al
inc bx ;偏移地址向前移动
loop s ;检测循环条件,符合就循环,否则向下继续
mov ax, 4c00h
int 21h
code ends
end
But I don't know what is the end CC21
???
Summarize
bx + loop can achieve the effect similar to for loop
mov bx, 0 ; i = 0
mov cx, 8 ; len = 8
s: push [bx]
inc bx ; i++
loop s ; i < len 循环
Inc self-increment is equivalent to i++
dec self-decrementi--