当前位置:网站首页>汇编实例解析--实模式下屏幕显示
汇编实例解析--实模式下屏幕显示
2022-07-03 16:48:00 【raindayinrain】
1.方式1
; 开机上电,先执行BIOS,再执行硬盘主引导程序,也即这里。
; 此时属于实模式,16位模式,此时主引导程序所在的物理内存位置是0x7c00
; 物理内存区域:0xb8000~0xbFFFF是显存区域。
; 显存模式80*25。每个字符占据2个字节,一个是字符ascii码,一个是显示格式。
mov ax,0xb800
mov es,ax
; es可用于数据物理内存寻址辅助段寄存器,默认是ds
mov byte [es:0x00],'L'
mov byte [es:0x01],0x07
mov byte [es:0x02],'a'
mov byte [es:0x03],0x07
mov byte [es:0x04],'b'
mov byte [es:0x05],0x07
mov byte [es:0x06],'e'
mov byte [es:0x07],0x07
mov byte [es:0x08],'l'
mov byte [es:0x09],0x07
mov byte [es:0x0a],' '
mov byte [es:0x0b],0x07
mov byte [es:0x0c],"o"
mov byte [es:0x0d],0x07
mov byte [es:0x0e],'f'
mov byte [es:0x0f],0x07
mov byte [es:0x10],'f'
mov byte [es:0x11],0x07
mov byte [es:0x12],'s'
mov byte [es:0x13],0x07
mov byte [es:0x14],'e'
mov byte [es:0x15],0x07
mov byte [es:0x16],'t'
mov byte [es:0x17],0x07
mov byte [es:0x18],':'
mov byte [es:0x19],0x07
; 进入主引导程序时候,cs内容是0x0000
mov cx,cs
mov ds,cx
mov ax,number
mov bx,10
mov dx,0
; dx:ax / bx,商放ax,余数放dx
div bx
mov [0x7c00+number+0x00],dl ; 存储余数,这是个位
xor dx,dx ; dx会被设置为0
div bx
mov [0x7c00+number+0x01],dl ; 存储余数,这是十位
xor dx,dx
div bx
mov [0x7c00+number+0x02],dl ; 存储余数,这是百位
xor dx,dx
div bx
mov [0x7c00+number+0x03],dl ; 存储余数,这是千位
xor dx,dx
div bx
mov [0x7c00+number+0x04],dl ; 存储余数,这是万位
mov al,[0x7c00+number+0x04]
add al,0x30 ; 这是将万位的十进制数值转化为ascii代码
mov [es:0x1a],al ; 继续向显存写入万位ascii
mov byte [es:0x1b],0x04
mov al,[0x7c00+number+0x03]
add al,0x30
mov [es:0x1c],al
mov byte [es:0x1d],0x04
mov al,[0x7c00+number+0x02]
add al,0x30
mov [es:0x1e],al
mov byte [es:0x1f],0x04
mov al,[0x7c00+number+0x01]
add al,0x30
mov [es:0x20],al
mov byte [es:0x21],0x04
mov al,[0x7c00+number+0x00]
add al,0x30
mov [es:0x22],al
mov byte [es:0x23],0x04
mov byte [es:0x24],'D'
mov byte [es:0x25],0x07
; 控制显存显示一段内容,接着显示number,接着显示D。
infi: jmp near infi
; 汇编语言支持标号,标号是一个数值。反映了指示位置的偏移量。
; 这里number反映了db所声明的5个1字节数据起始位置距离本程序起始位置的距离
number db 0,0,0,0,0
; 汇编支持times前缀,用于表示其后指令执行多少次。
; 声明203个1字节数据,占据连续的203存储空间。
times 203 db 0
; 主引导程序512字节,最后两个字节需要为0x55 0xaa
db 0x55,0xaa 2.方式2
jmp near start
mytext db 'L',0x07,'a',0x07,'b',0x07,'e',0x07,'l',0x07,' ',0x07,'o',0x07,\
'f',0x07,'f',0x07,'s',0x07,'e',0x07,'t',0x07,':',0x07
number db 0,0,0,0,0
start:
mov ax,0x7c0
mov ds,ax
mov ax,0xb800
mov es,ax
cld
mov si,mytext
mov di,0
mov cx,(number-mytext)/2
; 将ds:si处,cx个字,正向移动到es:di处
rep movsw
mov ax,number
mov bx,ax
mov cx,5
mov si,10
digit:
xor dx,dx ; dx设置为0
div si ; dx:ax / si,商ax,余数dx
mov [bx],dl ; 将个位存储到number标记的首个内存位置
inc bx
loop digit ; 循环执行digit,算上一开始执行的,共执行cx次
mov bx,number
mov si,4
show:
mov al,[bx+si] ; number标记位置第4个字节开始[从0计数]
add al,0x30 ; 转化得到字节的ascii码
mov ah,0x04 ; 显示属性
mov [es:di],ax ; 存储到显存中紧跟着前面标号字符串之后
add di,2
dec si
jns show ; 循环,直到dec si的结果变成负数,才停止循环继续执行。
mov word [es:di],0x0744
jmp near $
times 510-($-$$) db 0 ; $代表当前位置距离起始位置的偏移量。
db 0x55,0xaa 3.利用栈进行求和
jmp near start ; 跳转
message db '1+2+3+...+100='
start:
mov ax,0x7c0
mov ds,ax
mov ax,0xb800
mov es,ax
mov si,message
mov di,0
mov cx,start-message
@g:
mov al,[si] ; 从物理内存到寄存器
mov [es:di],al ; 从寄存器到物理内存,因为不支持直接从物理内存1到物理内存2
inc di
mov byte [es:di],0x07
inc di
inc si ; di指向显存位置2个字节来显示一个si处的字节
loop @g ; 通过cx控制次数
xor ax,ax ; ax清零
mov cx,1 ;
@f:
add ax,cx
inc cx
cmp cx,100
jle @f ; 只要比较结果是小于等于就继续循环
xor cx,cx
mov ss,cx
mov sp,cx
mov bx,10
xor cx,cx
@d:
inc cx
xor dx,dx
div bx ; dx:ax / bx,商ax,余数dx
or dl,0x30 ; 实现dl+0x30一样的效果
push dx ;利用栈的存储计算结果--个位,十位,...
cmp ax,0
jne @d ; 比较结果不是相等,继续循环
@a:
pop dx
mov [es:di],dl ; 将出栈的ascii字符复制到显存紧跟前面显示部分之后
inc di
mov byte [es:di],0x07
inc di
loop @a ; 通过cx来控制循环次数,每次到loop这里,cx先减去1,若此时cx为0,则无法继续循环。否则,继续循环。
jmp near $
times 510-($-$$) db 0
db 0x55,0xaa边栏推荐
- Necessary ability of data analysis
- Thread pool executes scheduled tasks
- 【剑指 Offer 】64. 求1+2+…+n
- Central South University | through exploration and understanding: find interpretable features with deep reinforcement learning
- Alibaba P8 painstakingly sorted it out. Summary of APP UI automated testing ideas. Check it out
- Svn usage specification
- CC2530 common registers for watchdog
- A survey of state of the art on visual slam
- CC2530 common registers for timer 1
- Overview of satellite navigation system
猜你喜欢

Network security web penetration technology

Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..

Basis of target detection (IOU)

关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM

斑马识别成狗,AI犯错的原因被斯坦福找到了

爱可可AI前沿推介(7.3)

What is the difference between 14Cr1MoR container plate and 14Cr1MoR (H)? Chemical composition and performance analysis of 14Cr1MoR

Arduino esp32: overall framework of lvgl project (I)

utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library

What is the material of 13mnnimor? 13mnnimor steel plate for medium and low temperature pressure vessels
随机推荐
为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”
Cocos Creator 2. X automatic packaging (build + compile)
BYD and great wall hybrid market "get together" again
"The NTP socket is in use, exiting" appears when ntpdate synchronizes the time
14 topics for performance interviews between superiors and subordinates (4)
Client does not support authentication protocol requested by server; consider upgrading MySQL client
RF Analyze Demo搭建 Step by Step
What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties
Extraction of the same pointcut
Mysql 将逗号隔开的属性字段数据由列转行
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
What is the pledge pool and how to pledge?
Summary of three methods of PHP looping through arrays list (), each (), and while
中南大学|通过探索理解: 发现具有深度强化学习的可解释特征
function overloading
MySQL Basics
Informatics Olympiad all in one YBT 1175: divide by 13 | openjudge noi 1.13 27: divide by 13
Recommendation of good books on learning QT programming
What is the material of sa302grc? American standard container plate sa302grc chemical composition
2022.02.14_ Daily question leetcode five hundred and forty