數字和數字根的總和
Problem statement:
問題陳述:
Write an assembly language program in 8086 microprocessor to find sum of digit of an 8 bits number using 8 bits operation.
在8086微處理器中編寫匯編語言程序,以使用8位運算找到8位數字的位數之和。
Assume 8 bit number is stored at memory location 2050.
假設8位數字存儲在存儲位置2050中。
Assumptions: Addresses of input data and output data are 2050 and 2051 respectively.
假設:輸入數據和輸出數據的地址分別為2050和2051。
Algorithm:
算法:
Load contents of memory location 2050 in register AL
將存儲單元2050中的內容加載到寄存器AL中
Copy content of register AL to register AH
將寄存器AL的內容復制到寄存器AH
Assign 0004 to CX Register Pair
將0004分配給CX寄存器對
Do AND operation on content of AL with 0F and store result in AL
用0F對AL的內容執行AND運算,并將結果存儲在AL中
Rotate the contents of AH by executing ROL instruction using CX
通過使用CX執行ROL指令來旋轉AH的內容
Do AND operation on content of AH with 0F and store result in AH
用0F對AH的內容執行AND運算并將結果存儲在AH中
Add AL and AH content and store result in AL
添加AL和AH內容并將結果存儲在AL中
Store the content of AL in memory location 2051
將AL的內容存儲在內存位置2051中
Program:
程序:
Mnemonics | Comments |
---|---|
MOV AL, [2050] | AL←[2050] |
MOV AH, AL | AH←AL |
MOV CX, 0004 | CX ← 0004 |
AND AL, 0F | AL ← AL & 0F |
ROL AH, CX | Rotate AH content left by 4 bits(value of CX) |
AND AH, 0F | AH ← AH & 0F |
ADD AL, AH | AL←AL+AH |
MOV [2051], AL | [2051]←AL |
HLT | Stop Execution |
助記符 | 注釋 |
---|---|
MOV AL,[2050] | AL←[2050] |
MO AH,AL | AH←AL |
MOV CX,0004 | CX←0004 |
AND AL,0F | AL←AL&0F |
ROL AH,CX | 將AH內容向左旋轉4位(CX值) |
AND AH,0F | AH←AH&0F |
AH,AD AL | AL←AL + AH |
MOV [2051],AL | [2051]←AL |
HLT | 停止執行 |
Explanation
說明
MOV AL, [2050]: loads contents of memory location 2050 in AL
MOV AL,[2050] :將存儲位置2050中的內容加載到AL中
MOV AH, AL: copy content of register AL to register AH
MOV AH,AL :將寄存器AL的內容復制到寄存器AH
MOV CX, 0004: assign 0004 to CX register pair
MOV CX,0004 :將0004分配給CX寄存器對
AND AL, 0F: does AND operation on content of AL with 0F and store result in AL
AND AL,0F :對具有0F的AL的內容執行AND運算并將結果存儲在AL中
ROL AH, CX: rotate the content of AH register left by 4 bits i.e. value of CX register pair
ROL AH,CX :將AH寄存器的內容向左旋轉4位,即CX寄存器對的值
AND AH, 0F: does AND operation on content of AH with 0F and store result in AH
AND AH,0F :用0F對AH的內容執行AND運算并將結果存儲在AH中
ADD AL, AH: add AL and AH content and store result in AL
添加AL,AH :添加AL和AH內容并將結果存儲在AL中
MOV [2051], AL: stores the content of AL in 2051 memory address
MOV [2051],AL :將AL的內容存儲在2051存儲器地址中
HLT: stops executing the program
HLT :停止執行程序
翻譯自: https://www.includehelp.com/embedded-system/find-sum-of-the-digits-of-an-8-bits-number-using-8086-microprocessor.aspx
數字和數字根的總和