当前位置:网站首页>汇编实例解析--实模式下屏幕显示
汇编实例解析--实模式下屏幕显示
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边栏推荐
- [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
- 远程办公之如何推进跨部门项目协作 | 社区征文
- Explore Netease's large-scale automated testing solutions see here see here
- CC2530 common registers for watchdog
- [combinatorics] non descending path problem (number of non descending paths with constraints)
- arduino-esp32:LVGL项目(一)整体框架
- "The NTP socket is in use, exiting" appears when ntpdate synchronizes the time
- Summary of three methods of PHP looping through arrays list (), each (), and while
- [combinatorics] recursive equation (example 1 of recursive equation | list recursive equation)
- 一台服务器最大并发 tcp 连接数多少?65535?
猜你喜欢

CC2530 common registers for serial communication

ucore概述

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

Recommendation of good books on learning QT programming

Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day

Visual SLAM algorithms: a survey from 2010 to 2016

美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃

CC2530 common registers for watchdog

Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford

word 退格键删除不了选中文本,只能按delete
随机推荐
LeetCode 1657. Determine whether the two strings are close
2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
What is the difference between 14Cr1MoR container plate and 14Cr1MoR (H)? Chemical composition and performance analysis of 14Cr1MoR
Recommendation of good books on learning QT programming
Deep understanding of grouping sets statements in SQL
AcWing 第58 场周赛
CC2530 common registers for ADC single channel conversion
Fast Ethernet and Gigabit Ethernet: what's the difference?
How programming apes grow rapidly
Capacités nécessaires à l'analyse des données
Mysql database DDL and DML
Leetcode binary search tree
One article takes you to understand machine learning
NSQ source code installation and operation process
QT serial port UI design and solution to display Chinese garbled code
[combinatorics] recursive equation (example 1 of recursive equation | list recursive equation)
A survey of state of the art on visual slam
RF Analyze Demo搭建 Step by Step
Svn usage specification
面试之 top k问题