当前位置:网站首页>汇编实例解析--实模式下屏幕显示
汇编实例解析--实模式下屏幕显示
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边栏推荐
- Data driving of appium framework for mobile terminal automated testing
- Informatics Olympiad all in one YBT 1175: divide by 13 | openjudge noi 1.13 27: divide by 13
- Construction practice camp - graduation summary of phase 6
- RF analyze demo build step by step
- On Lagrange interpolation and its application
- Meituan side: why does thread crash not cause JVM crash
- AcWing 第58 场周赛
- [combinatorial mathematics] counting model, common combinatorial numbers and combinatorial identities**
- Visual SLAM algorithms: a survey from 2010 to 2016
- arduino-esp32:LVGL项目(一)整体框架
猜你喜欢

Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer

Aike AI frontier promotion (7.3)

于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日

Shentong express expects an annual loss of nearly 1billion

CC2530 common registers for serial communication

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

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

PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
![[combinatorics] polynomial theorem (polynomial theorem | polynomial theorem proof | polynomial theorem inference 1 item number is the number of non negative integer solutions | polynomial theorem infe](/img/9d/6118b699c0d90810638f9b08d4f80a.jpg)
[combinatorics] polynomial theorem (polynomial theorem | polynomial theorem proof | polynomial theorem inference 1 item number is the number of non negative integer solutions | polynomial theorem infe

关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
随机推荐
PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
香港理工大学|数据高效的强化学习和网络流量动态的自适应最优周界控制
美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
[Jianzhi offer] 58 - ii Rotate string left
什么是质押池,如何进行质押呢?
Mysql 单表字段重复数据取最新一条sql语句
MySQL Basics
Learn from me about the enterprise flutter project: simplified framework demo reference
Record windows10 installation tensorflow-gpu2.4.0
IL Runtime
Interviewer: how does the JVM allocate and recycle off heap memory
Top k questions of interview
What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties
"The NTP socket is in use, exiting" appears when ntpdate synchronizes the time
远程办公之如何推进跨部门项目协作 | 社区征文
Data driving of appium framework for mobile terminal automated testing
What is the maximum number of concurrent TCP connections for a server? 65535?
RF Analyze Demo搭建 Step by Step
Visual SLAM algorithms: a survey from 2010 to 2016
斑马识别成狗,AI犯错的原因被斯坦福找到了