当前位置:网站首页>匯編實例解析--實模式下屏幕顯示
匯編實例解析--實模式下屏幕顯示
2022-07-03 16:49:00 【raindayinrain】
1.方式1
; 開機上電,先執行BIOS,再執行硬盤主引導程序,也即這裏。
; 此時屬於實模式,16比特模式,此時主引導程序所在的物理內存比特置是0x7c00
; 物理內存區域:0xb8000~0xbFFFF是顯存區域。
; 顯存模式80*25。每個字符占據2個字節,一個是字符ascii碼,一個是顯示格式。
mov ax,0xb800
mov es,ax
; es可用於數據物理內存尋址輔助段寄存器,默認是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
; 進入主引導程序時候,cs內容是0x0000
mov cx,cs
mov ds,cx
mov ax,number
mov bx,10
mov dx,0
; dx:ax / bx,商放ax,餘數放dx
div bx
mov [0x7c00+number+0x00],dl ; 存儲餘數,這是個比特
xor dx,dx ; dx會被設置為0
div bx
mov [0x7c00+number+0x01],dl ; 存儲餘數,這是十比特
xor dx,dx
div bx
mov [0x7c00+number+0x02],dl ; 存儲餘數,這是百比特
xor dx,dx
div bx
mov [0x7c00+number+0x03],dl ; 存儲餘數,這是千比特
xor dx,dx
div bx
mov [0x7c00+number+0x04],dl ; 存儲餘數,這是萬比特
mov al,[0x7c00+number+0x04]
add al,0x30 ; 這是將萬比特的十進制數值轉化為ascii代碼
mov [es:0x1a],al ; 繼續向顯存寫入萬比特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
; 控制顯存顯示一段內容,接著顯示number,接著顯示D。
infi: jmp near infi
; 匯編語言支持標號,標號是一個數值。反映了指示比特置的偏移量。
; 這裏number反映了db所聲明的5個1字節數據起始比特置距離本程序起始比特置的距離
number db 0,0,0,0,0
; 匯編支持times前綴,用於錶示其後指令執行多少次。
; 聲明203個1字節數據,占據連續的203存儲空間。
times 203 db 0
; 主引導程序512字節,最後兩個字節需要為0x55 0xaa
db 0x55,0xaa 2.方式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
; 將ds:si處,cx個字,正向移動到es:di處
rep movsw
mov ax,number
mov bx,ax
mov cx,5
mov si,10
digit:
xor dx,dx ; dx設置為0
div si ; dx:ax / si,商ax,餘數dx
mov [bx],dl ; 將個比特存儲到number標記的首個內存比特置
inc bx
loop digit ; 循環執行digit,算上一開始執行的,共執行cx次
mov bx,number
mov si,4
show:
mov al,[bx+si] ; number標記比特置第4個字節開始[從0計數]
add al,0x30 ; 轉化得到字節的ascii碼
mov ah,0x04 ; 顯示屬性
mov [es:di],ax ; 存儲到顯存中緊跟著前面標號字符串之後
add di,2
dec si
jns show ; 循環,直到dec si的結果變成負數,才停止循環繼續執行。
mov word [es:di],0x0744
jmp near $
times 510-($-$$) db 0 ; $代錶當前比特置距離起始比特置的偏移量。
db 0x55,0xaa 3.利用棧進行求和
jmp near start ; 跳轉
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] ; 從物理內存到寄存器
mov [es:di],al ; 從寄存器到物理內存,因為不支持直接從物理內存1到物理內存2
inc di
mov byte [es:di],0x07
inc di
inc si ; di指向顯存比特置2個字節來顯示一個si處的字節
loop @g ; 通過cx控制次數
xor ax,ax ; ax清零
mov cx,1 ;
@f:
add ax,cx
inc cx
cmp cx,100
jle @f ; 只要比較結果是小於等於就繼續循環
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,商ax,餘數dx
or dl,0x30 ; 實現dl+0x30一樣的效果
push dx ;利用棧的存儲計算結果--個比特,十比特,...
cmp ax,0
jne @d ; 比較結果不是相等,繼續循環
@a:
pop dx
mov [es:di],dl ; 將出棧的ascii字符複制到顯存緊跟前面顯示部分之後
inc di
mov byte [es:di],0x07
inc di
loop @a ; 通過cx來控制循環次數,每次到loop這裏,cx先减去1,若此時cx為0,則無法繼續循環。否則,繼續循環。
jmp near $
times 510-($-$$) db 0
db 0x55,0xaa边栏推荐
- [mathematical logic] equivalent calculus and reasoning calculus of propositional logic (propositional logic | equivalent calculus | principal conjunctive (disjunctive) paradigm | reasoning calculus)**
- Thread pool executes scheduled tasks
- 为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”
- BYD and great wall hybrid market "get together" again
- Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
- Daily code 300 lines learning notes day 10
- CC2530 common registers for timer 1
- [combinatorial mathematics] counting model, common combinatorial numbers and combinatorial identities**
- [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
- Extraction of the same pointcut
猜你喜欢

Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
![[solved] access denied for user 'root' @ 'localhost' (using password: yes)](/img/71/1ff8ed1d773da99054310f96dca3f8.jpg)
[solved] access denied for user 'root' @ 'localhost' (using password: yes)

Mysql 将逗号隔开的属性字段数据由列转行

斑马识别成狗,AI犯错的原因被斯坦福找到了

What kind of material is 14Cr1MoR? Analysis of chemical composition and mechanical properties of 14Cr1MoR

于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日

一台服务器最大并发 tcp 连接数多少?65535?

What material is sa537cl2? Analysis of mechanical properties of American standard container plate

(补)双指针专题

CC2530 common registers for watchdog
随机推荐
What material is sa537cl2? Analysis of mechanical properties of American standard container plate
Client does not support authentication protocol requested by server; consider upgrading MySQL client
Capacités nécessaires à l'analyse des données
Data driving of appium framework for mobile terminal automated testing
Visual SLAM algorithms: a survey from 2010 to 2016
Recommendation of good books on learning QT programming
中南大学|通过探索理解: 发现具有深度强化学习的可解释特征
Threejs Part 2: vertex concept, geometry structure
Is it safe to open a stock account by mobile registration? Does it need money to open an account
[sword finger offer] 58 - I. flip the word order
Eleven requirements for test management post
arduino-esp32:LVGL项目(一)整体框架
(Supplement) double pointer topic
【剑指 Offer 】64. 求1+2+…+n
ucore概述
Visual SLAM algorithms: a survey from 2010 to 2016
PHP production website active push (website)
13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties
14 topics for performance interviews between superiors and subordinates (4)
LeetCode 1658. Minimum operand to reduce x to 0