《汇编语言简明教程》笔记


前言

提示:最近在学习汇编,简单的做一下源码笔记。


一、环境

win7 (x86)、ML615文件夹(包含汇编需要的各种软件)

二、编译过程

1.流程

  1. 打开ml.exe,进入DOS界面
  2. 使用命令 ml 1.asm (1.asm为自己编写的汇编程序文件),生成文件 1.exe
  3. 运行程序 1.exe

2.asm程序模板

代码如下(示例):

;此处的分号为注释
.model small
.stack
.data
msg db'hello world', 13,10,'$'
.code
.startup
mov dx,offset msg
mov ah,9
int 21h
.exit
end

三、书中示例源码

  • 例3-5 大小写字母转换程序
.model small
.stack
.data
msg db'welcome', '$'
.code
.startup
	mov cx,(lengthof msg)-1
	mov bx,0
again:sub msg[bx],20H	;或者是 again:sub msg[bx],'a'-'A';
	inc bx
	loop again
	mov dx,offset msg
	mov ah,9
	int 21h
.exit
end
  • 例3-6 温度转换程序
.data
tempc dw 26
tempf dw ?
.code
.startup
mov ax,tempc
mov bx,9
imul bx
mov bx,5
idiv bx
add ax,32
mov tempf,ax
mov dx,offset tempf
mov ah,9
int 21h
.exit
end 

通过汇编查看结果,得知CX=003A

  • 例3-8 移位指令实现乘法程序
 include io.inc
.model small
.stack
.data
bvar db 64
.code
.startup
xor ax,ax
mov al,bvar
shl ax,1
mov bx,ax
shl ax,1
shl ax,1
add ax,bx

mov bx,10
mul bx
call dispuiw
.exit
end   
  • 带进位循环右移,举例:
执行前:AL=11100101B,CL=4,CF=0
执行后:AL=10101110B,CL=4,CF=0
过程:1.将AL进位补上,即为:AL=011100101B
2.将头4位移到后面,带上进位,即需要移动5位到后面
3.移位后,结果是AL=010101110B,不显示进位,即是AL=10101110B
  • 例4-2 读取CMOS RAM数据程序
;CMOS RAM
.model small
.stack
.data
dates db'2021-09-14','$'

.code
.startup
mov bx,offset dates+2
mov cl,4
mov al,9
out 70h,al
in al,71h
mov ah,al
shr ah,cl
or ah,30h
mov[bx],ah
inc bx
and al,0fh
or al,30h
mov[bx],al
add bx,2
mov al,8
out 70h,al
in al,71h
mov ah,al
shr ah,cl
or ah,30h
mov[bx],ah
shr ah,cl
or al,30h
mov[bx],al
add bx,2
mov al,7
out 70h,al
in al,71h
mov ah,al
shr ah,cl
or ah,cl
or ah,30h
mov [bx],ah
inc bx
and al,0fh
or al,30h
mov[bx],al
mov dx,offset dates
mov ah,9
int 21h
.exit
end
  • 4-4 个数折半程序
;个数折半程序
include IO.INC
.model small
.stack
.data
.code
.startup
mov ax,885
shr ax,1
jnc goeven
add ax,1
goeven: call dispuiw
.exit
end 
  • 例4-13 数组求和
;数组求和
include IO.INC
.model small
.stack
.data
array dw 136,-138,133,130,-161
sum dw ?
.code
.startup
xor ax,ax
mov cx,lengthof array
mov bx,offset array
again: 	add ax,[bx]
		add bx,type array
loop again
mov sum,ax
;mov ah,9
;int 21h
call dispuiw
.exit
end 
  • 4-18 冒泡排序
;冒泡排序
include IO.INC
.model small
.stack
.data
array dw 587,-632,777,234,-34
count = lengthof array
.code
.startup
mov cx,count
dec cx
outlp:
	mov dx,cx
	mov bx,offset array	
inlp:
	mov ax,[bx]
	cmp ax,[bx+1]
	jng next
	xchg ax,[bx+1]
	mov [bx],ax	
next:
	inc bx
	dec dx
	jnz inlp
loop outlp
;mov ah,9
;int 21h
;mov dx,offset array
call dispuiw
.exit
end 

总结

提示:自己学习笔记。好记性不如烂笔头。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Qter_Sean

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值