当前位置: 首页 > 工具软件 > JCC > 使用案例 >

汇编语言(6)使用JCC指令构造分支与循环

糜俊彦
2023-12-01

1 数据段的使用

汇编语言打印字符串。

assume cs:code,ds:data

data segment
	buffer db 0DH,0AH,'day3$'
data ends

code segment
main proc
	mov ax,data
	mov ds,ax
	mov dx,offset buffer
	mov ah,09H
	int 21H
	mov ah,07H
	int 21H
	mov ax,4C00H
	int 21H
main endp
start:call main
code ends
end start

2 flag寄存器

CMP OPRD1,OPRD1
SUB影响标志位
AX = 8
BX = 8
相等 AX - BX = 0 ZF = 1

AX = 8
BX = 1
不相等 AX - BX != 0 ZF = 0

AX < BX:发生借位
CF = 1
AX > BX:不发生借位
AX - BX = ?CF = 0 ZF = 0
AX <= BX:
AX - BX = ? CF = 1 || ZF = 1
AX >= BX:
AX - BX = ? CF = 0 || ZF = 1

一类 JCC 指令 跳转
JMP address
JE 条件转移指令 等于则跳转 ZF = 1
JNE 不等于则跳转 ZF = 0
JB 低于则跳转 CF = 1
JA 高于则跳转 CF = 0 && ZF = 0
JNA 小于等于则跳转 CF = 1 或者 ZF = 1
JNB 大于等于则跳转 CF = 0

3 跳转

assume cs:code,ds:data

data segment
	buffer db 0DH,0AH,'day3$'
	buffer1 db 0DH,0AH,'day2$'
data ends

code segment
main proc
	mov ax,data
	mov ds,ax
	mov dx,offset buffer
	mov ah,09H
	int 21H
	jmp qq1
	mov dx,offset buffer1
	mov ah,09H
	int 21H
qq1:
	mov ah,07H
	int 21H
	mov ax,4C00H
	int 21H
main endp
start:call main
code ends
end start

创造跳转条件

assume cs:code,ds:data

data segment
	buffer db 0DH,0AH,'day3$'
	buffer1 db 0DH,0AH,'day2$'
data ends

code segment
main proc
	mov ax,data
	mov ds,ax
	mov dx,offset buffer
	mov ah,09H
	int 21H

	mov ax,1
	mov bx,2
	cmp ax,bx
	ja qq1
	
	mov dx,offset buffer1
	mov ah,09H
	int 21H
qq1:
	mov ah,07H
	int 21H
	mov ax,4C00H
	int 21H
main endp
start:call main
code ends
end start

需要满足多个条件则依次判断是否满足条件。
循环

for(int i = 0; i <= 100; i ++)

mov cx,0
qq2:
cmp cx,100
ja qq
	mov dx,offset buffer
	mov ah,09H
	int 21H
	inc cx
	jmp qq2
qq:

mov cx,0
qq2:
	mov dx,offset buffer
	mov ah,09H
	int 21H
	inc cx
	cmp cx,100
	jb qq2
 类似资料: