当前位置:网站首页>Assembly instance analysis -- screen display in real mode
Assembly instance analysis -- screen display in real mode
2022-07-03 16:50:00 【raindayinrain】
1. The way 1
; Turn on the power , Execute first BIOS, Then execute the hard disk main boot program , That is, here .
; At this time, it belongs to real mode ,16 Bit mode , At this time, the physical memory location of the main boot program is 0x7c00
; Physical memory area :0xb8000~0xbFFFF It's a video memory area .
; Video memory mode 80*25. Each character occupies 2 Bytes , One is a character ascii code , One is display format .
mov ax,0xb800
mov es,ax
; es Can be used for data physical memory addressing auxiliary segment register , The default is 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
; When entering the main boot program ,cs The content is 0x0000
mov cx,cs
mov ds,cx
mov ax,number
mov bx,10
mov dx,0
; dx:ax / bx, Commercial release ax, Put the remainder dx
div bx
mov [0x7c00+number+0x00],dl ; Store the remainder , This is a bit
xor dx,dx ; dx Will be set to 0
div bx
mov [0x7c00+number+0x01],dl ; Store the remainder , Here are ten
xor dx,dx
div bx
mov [0x7c00+number+0x02],dl ; Store the remainder , This is a hundred
xor dx,dx
div bx
mov [0x7c00+number+0x03],dl ; Store the remainder , This is a thousand
xor dx,dx
div bx
mov [0x7c00+number+0x04],dl ; Store the remainder , This is 10000
mov al,[0x7c00+number+0x04]
add al,0x30 ; This is to convert ten thousand decimal values into ascii Code
mov [es:0x1a],al ; Continue to write 10000 bits to the video memory 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
; Control the video memory to display a piece of content , Then... Is displayed number, Then... Is displayed D.
infi: jmp near infi
; Assembly language supports labeling , The label is a number . Reflects the offset of the indicated position .
; here number Reflects db The stated 5 individual 1 The distance between the starting position of byte data and the starting position of this program
number db 0,0,0,0,0
; Assembly support times Prefix , Used to indicate how many times the subsequent instruction is executed .
; Statement 203 individual 1 Bytes of data , Occupy a continuous 203 Storage space .
times 203 db 0
; Master bootstrap 512 byte , The last two bytes need to be 0x55 0xaa
db 0x55,0xaa
2. The way 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
; take ds:si It's about ,cx A word , Move forward to es:di It's about
rep movsw
mov ax,number
mov bx,ax
mov cx,5
mov si,10
digit:
xor dx,dx ; dx Set to 0
div si ; dx:ax / si, merchant ax, remainder dx
mov [bx],dl ; Store bits in number The first memory location marked
inc bx
loop digit ; Loop execution digit, Count the first execution , In total cx Time
mov bx,number
mov si,4
show:
mov al,[bx+si] ; number Mark position No 4 Bytes start [ from 0 Count ]
add al,0x30 ; Converted to bytes ascii code
mov ah,0x04 ; Display properties
mov [es:di],ax ; Stored in video memory immediately after the preceding label string
add di,2
dec si
jns show ; loop , until dec si The result of becomes negative , Just stop the cycle and continue to execute .
mov word [es:di],0x0744
jmp near $
times 510-($-$$) db 0 ; $ Represents the offset of the current position from the starting position .
db 0x55,0xaa
3. Use stack to sum
jmp near start ; Jump
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] ; From physical memory to registers
mov [es:di],al ; From register to physical memory , Because it does not support directly from physical memory 1 To physical memory 2
inc di
mov byte [es:di],0x07
inc di
inc si ; di Point to the video memory location 2 Bytes to display a si Byte at
loop @g ; adopt cx Control times
xor ax,ax ; ax Zero clearing
mov cx,1 ;
@f:
add ax,cx
inc cx
cmp cx,100
jle @f ; As long as the comparison result is less than or equal to, continue the cycle
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, merchant ax, remainder dx
or dl,0x30 ; Realization dl+0x30 Same effect
push dx ; Use the stack to store the calculation results -- bits , ten ,...
cmp ax,0
jne @d ; The comparison results are not equal , Continue to cycle
@a:
pop dx
mov [es:di],dl ; Will be out of the stack ascii The characters are copied to the video memory immediately after the previous display
inc di
mov byte [es:di],0x07
inc di
loop @a ; adopt cx To control the number of cycles , Every time I come to loop here ,cx First subtract 1, If at this time cx by 0, Cannot continue the cycle . otherwise , Continue to cycle .
jmp near $
times 510-($-$$) db 0
db 0x55,0xaa
边栏推荐
- 面试之 top k问题
- Kindeditor editor upload image ultra wide automatic compression -php code
- 比亚迪、长城混动市场再“聚首”
- [combinatorics] non descending path problem (number of non descending paths with constraints)
- (补)双指针专题
- Preventing/catching “IllegalArgumentException: parameter must be a descendant of this view” error
- 美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
- To resist 7-Zip, list "three sins"? Netizen: "is the third key?"
- 执行脚本不认\r
- Nifi from introduction to practice (nanny level tutorial) - flow
猜你喜欢
QT串口ui设计和解决显示中文乱码
一台服务器最大并发 tcp 连接数多少?65535?
Processing strategy of message queue message loss and repeated message sending
MySQL single table field duplicate data takes the latest SQL statement
8 cool visual charts to quickly write the visual analysis report that the boss likes to see
QT serial port UI design and solution to display Chinese garbled code
CC2530 common registers for ADC single channel conversion
美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
What is the maximum number of concurrent TCP connections for a server? 65535?
2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
随机推荐
Network security web penetration technology
Arduino esp32: overall framework of lvgl project (I)
Record windows10 installation tensorflow-gpu2.4.0
CC2530 common registers for serial communication
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
CC2530 common registers for ADC single channel conversion
How to allow remote connection to MySQL server on Linux system?
[combinatorics] polynomial theorem (polynomial coefficients | full arrangement of multiple sets | number of schemes corresponding to the ball sub model | polynomial coefficient correlation identity)
Overview of satellite navigation system
[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
关于学习Qt编程的好书精品推荐
[combinatorial mathematics] counting model, common combinatorial numbers and combinatorial identities**
Daily code 300 lines learning notes day 10
Summary of three methods of PHP looping through arrays list (), each (), and while
Visual SLAM algorithms: a survey from 2010 to 2016
Client does not support authentication protocol requested by server; consider upgrading MySQL client
Develop team OKR in the way of "crowdfunding"
mysql用户管理
【剑指 Offer 】57 - II. 和为s的连续正数序列
Mysql 单表字段重复数据取最新一条sql语句