当前位置:网站首页>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边栏推荐
- Overview of satellite navigation system
- Thread pool executes scheduled tasks
- [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
- Mysql database -dql
- Top k questions of interview
- BYD and great wall hybrid market "get together" again
- RF Analyze Demo搭建 Step by Step
- Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
- Nifi from introduction to practice (nanny level tutorial) - flow
- To resist 7-Zip, list "three sins"? Netizen: "is the third key?"
猜你喜欢

There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them

What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties

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

Mysql 单表字段重复数据取最新一条sql语句

The word backspace key cannot delete the selected text, so you can only press Delete

CC2530 common registers for port initialization

Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..

8 cool visual charts to quickly write the visual analysis report that the boss likes to see

Fast Ethernet and Gigabit Ethernet: what's the difference?

Netease UI automation test exploration: airtest+poco
随机推荐
[combinatorics] non descending path problem (number of non descending paths with constraints)
CC2530 common registers for serial communication
PHP secondary domain name session sharing scheme
Mongodb installation and basic operation
Web crawler knowledge day03
How to delete a specific line from a text file using the SED command?
【剑指 Offer】58 - I. 翻转单词顺序
What is the material of sa302grc? American standard container plate sa302grc chemical composition
[Jianzhi offer] 64 Find 1+2+... +n
斑马识别成狗,AI犯错的原因被斯坦福找到了
跟我学企业级flutter项目:简化框架demo参考
Shentong express expects an annual loss of nearly 1billion
(Supplement) double pointer topic
Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
To resist 7-Zip, list "three sins"? Netizen: "is the third key?"
The word backspace key cannot delete the selected text, so you can only press Delete
Add color to the interface automation test framework and realize the enterprise wechat test report
BYD and great wall hybrid market "get together" again
消息队列消息丢失和消息重复发送的处理策略
Arduino esp32: overall framework of lvgl project (I)