当前位置:网站首页>汇编实例解析--实模式下屏幕显示
汇编实例解析--实模式下屏幕显示
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边栏推荐
- CC2530 common registers for timer 1
- Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
- BYD and great wall hybrid market "get together" again
- IDEA-配置插件
- Svn usage specification
- Extraction of the same pointcut
- 14 topics for performance interviews between superiors and subordinates (4)
- QT串口ui设计和解决显示中文乱码
- arduino-esp32:LVGL项目(一)整体框架
- Visual SLAM algorithms: a survey from 2010 to 2016
猜你喜欢

Interviewer: how does the JVM allocate and recycle off heap memory

Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs

Mysql 将逗号隔开的属性字段数据由列转行

Add color to the interface automation test framework and realize the enterprise wechat test report

什么是质押池,如何进行质押呢?

NLP four paradigms: paradigm 1: fully supervised learning in the era of non neural networks (Feature Engineering); Paradigm 2: fully supervised learning based on neural network (Architecture Engineeri

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

【LeetCode】94. Middle order traversal of binary tree

Mysql database -dql

斑馬識別成狗,AI犯錯的原因被斯坦福找到了
随机推荐
Unreal_ Datatable implements ID self increment and sets rowname
RF analyze demo build step by step
Interpretation of several important concepts of satellite antenna
[mathematical logic] equivalent calculus and reasoning calculus of propositional logic (propositional logic | equivalent calculus | principal conjunctive (disjunctive) paradigm | reasoning calculus)**
Mongodb installation and basic operation
On Lagrange interpolation and its application
8 cool visual charts to quickly write the visual analysis report that the boss likes to see
Golang decorator mode and its use in NSQ
美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
How to promote cross department project collaboration | community essay solicitation
RF Analyze Demo搭建 Step by Step
Learn from me about the enterprise flutter project: simplified framework demo reference
深入理解 SQL 中的 Grouping Sets 语句
ucore概述
Svn usage specification
TCP congestion control details | 3 design space
Mysql 将逗号隔开的属性字段数据由列转行
word 退格键删除不了选中文本,只能按delete
Deep understanding of grouping sets statements in SQL
什么是质押池,如何进行质押呢?