8051 程式以疊加兩個 8 位數
英特爾 8051 是一款 8 位微控制器。它擁有許多強大的指令和 IO 訪問技術。本節我們將瞭解如何使用 8051 進行其中一項最簡單的程式設計。
在這裡我們將使用此微控制器疊加兩個 8 位數。暫存器 A(累加器)用作操作中的一種運算元。在不同的暫存器庫中有七個暫存器 R0 – R7。我們可以使用其中的任何一個作為第二個運算元。
我們在位置 20H 和 21H 上取兩個數字 5FH 和 D8H,在疊加它們之後,結果將儲存在位置 30H 和 31H。
| 地址 | 值 |
|---|---|
| . . . | |
| 20H | 5FH |
| 21H | D8H |
| . . . | |
| 30H | 00H |
| 31H | 00H |
| . . . |
程式
MOVR0,#20H;set source address 20H to R0 MOVR1,#30H;set destination address 30H to R1 MOVA,@R0; take the value from source to register A MOVR5,A; Move the value from A to R5 MOVR4,#00H; Clear register R4 to store carry INCR0; Point to the next location MOVA,@R0; take the value from source to register A ADDA,R5;Add R5 with A and store to register A JNC SAVE INCR4; Increment R4 to get carry MOVB,R4;Get carry to register B MOV@R1,B; Store the carry first INCR1; Increase R1 to point to the next address SAVE: MOV@R1,A;Store the result HALT: SJMP HALT ;Stop the program
因此,透過疊加 5FH + D8H,結果為 137H。01H 將儲存在 30H,37 儲存在 31H。
輸出
| 地址 | 值 |
|---|---|
| . . . | |
| 20H | 5FH |
| 21H | D8H |
| . . . | |
| 30H | 01H |
| 31H | 37H |
| . . . |
廣告
資料結構
網路連線
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP