当前位置:网站首页>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
边栏推荐
- 2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
- [combinatorics] non descending path problem (number of non descending paths with constraints)
- "The NTP socket is in use, exiting" appears when ntpdate synchronizes the time
- Kotlin学习快速入门(7)——扩展的妙用
- Develop team OKR in the way of "crowdfunding"
- Informatics Olympiad all in one YBT 1175: divide by 13 | openjudge noi 1.13 27: divide by 13
- MySQL single table field duplicate data takes the latest SQL statement
- There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them
- Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
- What is the pledge pool and how to pledge?
猜你喜欢
Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
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
CC2530 common registers for timer 1
Data driving of appium framework for mobile terminal automated testing
什么是质押池,如何进行质押呢?
Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
Threejs Part 2: vertex concept, geometry structure
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
Fast Ethernet and Gigabit Ethernet: what's the difference?
随机推荐
Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
Summary of three methods of PHP looping through arrays list (), each (), and while
关于学习Qt编程的好书精品推荐
面试之 top k问题
[combinatorics] recursive equation (outline of recursive equation content | definition of recursive equation | example description of recursive equation | Fibonacci Series)
(补)双指针专题
远程办公之如何推进跨部门项目协作 | 社区征文
PHP CI (CodeIgniter) log level setting
CC2530 common registers for crystal oscillator settings
[combinatorics] recursive equation (example 1 of recursive equation | list recursive equation)
Necessary ability of data analysis
A survey of state of the art on visual slam
关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
How programming apes grow rapidly
Alibaba P8 painstakingly sorted it out. Summary of APP UI automated testing ideas. Check it out
What is the material of sa302grc? American standard container plate sa302grc chemical composition
[combinatorics] non descending path problem (number of non descending paths with constraints)
美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
(Supplement) double pointer topic
數據分析必備的能力