大小写转换
;Code Title:将小写转大写
;Author:MetaNetworks
;Date:2019-03-21
assume cs:start,ds:data
data segment
db '1. first '
db '2. second '
db '3. third '
db '4. fourth '
data ends
start:
mov ax,data
mov ds,ax
mov bx,0
mov cx,4
s:
push bx;储存此时的bx偏移
push cx
mov cx,13D
inner:
mov al,[bx]
;输出
check_A_Z_left:
cmp al,61h
jb NoNeed
check_A_Z_right:
cmp al,7Ah
ja NoNeed
process:
and al,11011111B
NoNeed:
mov dl,al
mov ah,2
int 21h
inc bx
loop inner
pop cx
pop bx
add bx,0Dh
;换行
mov dl, 10
mov ah, 02h
int 21h
mov dl, 13
mov ah, 02h
int 21h
;循环
loop s
;return
mov ax,4c00h
int 21h
end start
end
心得
- 条件语句用jmp(包括ja,jb,jae等等)指令是跳转到处理不符合条件的代码段,并且并不会像call一样在执行完代码段后返回原调用段,所以需要我们仔细分析代码段的顺序,串行看,程序走的就是最坏的执行路径.
遗留问题
参考
1
2
3
4
5
6
7
8
9
10
| int main(){
int a=5;
int b=3;
if(a>3 && b>10){
b=5;
}
else b=9;
b=7;
return 0;
}
|
.subsections_via_symbols
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 10, 14
.globl _main ## -- Begin function main
.p2align 4, 0x90
_main: ## @main
.cfi_startproc
## %bb.0:
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
movl $0, -4(%rbp)
movl $5, -8(%rbp)
movl $3, -12(%rbp)
cmpl $3, -8(%rbp)
jle LBB0_3
## %bb.1:
cmpl $10, -12(%rbp)
jle LBB0_3
## %bb.2:
movl $5, -12(%rbp)
jmp LBB0_4
LBB0_3:
movl $9, -12(%rbp)
LBB0_4:
xorl %eax, %eax
movl $7, -12(%rbp)
popq %rbp
retq
.cfi_endproc
## -- End function
.subsections_via_symbols