当前位置:网站首页>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边栏推荐
- Necessary ability of data analysis
- Develop team OKR in the way of "crowdfunding"
- [Jianzhi offer] 64 Find 1+2+... +n
- CC2530 common registers for timer 1
- One article takes you to understand machine learning
- Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day
- What material is sa537cl2? Analysis of mechanical properties of American standard container plate
- What is the material of 13mnnimor? 13mnnimor steel plate for medium and low temperature pressure vessels
- 13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties
- Daily code 300 lines learning notes day 10
猜你喜欢

Record windows10 installation tensorflow-gpu2.4.0

Aike AI frontier promotion (7.3)

Bcvp developer community 2022 exclusive peripheral first bullet

Arduino esp32: overall framework of lvgl project (I)

Basis of target detection (IOU)

网络安全web渗透技术

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

What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material

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

Visual SLAM algorithms: a survey from 2010 to 2016
随机推荐
Eleven requirements for test management post
What kind of material is 14Cr1MoR? Analysis of chemical composition and mechanical properties of 14Cr1MoR
Unreal_ Datatable implements ID self increment and sets rowname
Mysql database -dql
[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
[mathematical logic] equivalent calculus and reasoning calculus of propositional logic (propositional logic | equivalent calculus | principal conjunctive (disjunctive) paradigm | reasoning calculus)**
Svn usage specification
[solved] access denied for user 'root' @ 'localhost' (using password: yes)
What is the material of 13mnnimor? 13mnnimor steel plate for medium and low temperature pressure vessels
【剑指 Offer】58 - II. 左旋转字符串
面试之 top k问题
Is it safe to open a stock account by mobile registration? Does it need money to open an account
Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
What material is 12cr1movr? Chemical property analysis of pressure vessel steel plate 12cr1movr
Golang anonymous function use
Mysql 将逗号隔开的属性字段数据由列转行
Zebras are recognized as dogs, and Stanford found the reason why AI made mistakes
【剑指 Offer】58 - I. 翻转单词顺序
Recommendation of good books on learning QT programming
[combinatorial mathematics] counting model, common combinatorial numbers and combinatorial identities**