当前位置:网站首页>匯編實例解析--實模式下屏幕顯示
匯編實例解析--實模式下屏幕顯示
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边栏推荐
- Threejs Part 2: vertex concept, geometry structure
- 【LeetCode】94. Middle order traversal of binary tree
- PHP secondary domain name session sharing scheme
- Unreal_ Datatable implements ID self increment and sets rowname
- Informatics Olympiad all in one YBT 1175: divide by 13 | openjudge noi 1.13 27: divide by 13
- Caching mechanism of Hibernate / session level caching mechanism
- [combinatorics] recursive equation (outline of recursive equation content | definition of recursive equation | example description of recursive equation | Fibonacci Series)
- 关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
- 14 topics for performance interviews between superiors and subordinates (4)
- What is the pledge pool and how to pledge?
猜你喜欢
![[solved] access denied for user 'root' @ 'localhost' (using password: yes)](/img/71/1ff8ed1d773da99054310f96dca3f8.jpg)
[solved] access denied for user 'root' @ 'localhost' (using password: yes)
智慧之道(知行合一)

2022爱分析· 国央企数字化厂商全景报告

Visual SLAM algorithms: a survey from 2010 to 2016

什么是质押池,如何进行质押呢?

Daily code 300 lines learning notes day 10

What is the material of sa302grc? American standard container plate sa302grc chemical composition

CC2530 common registers for watchdog

word 退格键删除不了选中文本,只能按delete

Shentong express expects an annual loss of nearly 1billion
随机推荐
一台服务器最大并发 tcp 连接数多少?65535?
IDEA-配置插件
LeetCode 1658. Minimum operand to reduce x to 0
arduino-esp32:LVGL项目(一)整体框架
Data driving of appium framework for mobile terminal automated testing
Summary of three methods of PHP looping through arrays list (), each (), and while
Hong Kong Polytechnic University | data efficient reinforcement learning and adaptive optimal perimeter control of network traffic dynamics
How to set up SVN server on this machine
數據分析必備的能力
mysql用户管理
word 退格键删除不了选中文本,只能按delete
8 cool visual charts to quickly write the visual analysis report that the boss likes to see
What is the maximum number of concurrent TCP connections for a server? 65535?
MySQL converts comma separated attribute field data from column to row
[combinatorics] polynomial theorem (polynomial coefficients | full arrangement of multiple sets | number of schemes corresponding to the ball sub model | polynomial coefficient correlation identity)
CC2530 common registers for port interrupts
比亚迪、长城混动市场再“聚首”
Custom plug-in construction and use of QT plug-in
关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
CC2530 common registers for port initialization