当前位置:网站首页>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边栏推荐
- CC2530 common registers for port initialization
- What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material
- Network security web penetration technology
- [Jianzhi offer] 64 Find 1+2+... +n
- What is the pledge pool and how to pledge?
- 中南大学|通过探索理解: 发现具有深度强化学习的可解释特征
- CC2530 common registers
- (补)双指针专题
- 面试之 top k问题
- MySQL converts comma separated attribute field data from column to row
猜你喜欢

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

Visual SLAM algorithms: a survey from 2010 to 2016

arduino-esp32:LVGL项目(一)整体框架

2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises

Idea configuration plug-in

Daily code 300 lines learning notes day 10
智慧之道(知行合一)

MySQL single table field duplicate data takes the latest SQL statement

Cocos Creator 2. X automatic packaging (build + compile)

跟我学企业级flutter项目:简化框架demo参考
随机推荐
How to delete a specific line from a text file using the SED command?
Why is WPA3 security of enterprise business so important?
QT serial port UI design and solution to display Chinese garbled code
What is the material of 13mnnimor? 13mnnimor steel plate for medium and low temperature pressure vessels
2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
word 退格键删除不了选中文本,只能按delete
Daily code 300 lines learning notes day 10
Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
Simulink oscilloscope data is imported into Matlab and drawn
Execute script unrecognized \r
Top k questions of interview
Acwing game 58
MySQL Basics
LeetCode 1657. Determine whether the two strings are close
NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)
Is it safe to open a stock account by mobile registration? Does it need money to open an account
面试之 top k问题
Nifi from introduction to practice (nanny level tutorial) - flow
13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties