数字和数字根的总和_使用8086微处理器查找8位数字的数字总和

数字和数字根的总和

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:

算法:

  1. Load contents of memory location 2050 in register AL

    将存储单元2050中的内容加载到寄存器AL中

  2. Copy content of register AL to register AH

    将寄存器AL的内容复制到寄存器AH

  3. Assign 0004 to CX Register Pair

    将0004分配给CX寄存器对

  4. Do AND operation on content of AL with 0F and store result in AL

    用0F对AL的内容执行AND运算,并将结果存储在AL中

  5. Rotate the contents of AH by executing ROL instruction using CX

    通过使用CX执行ROL指令来旋转AH的内容

  6. Do AND operation on content of AH with 0F and store result in AH

    用0F对AH的内容执行AND运算并将结果存储在AH中

  7. Add AL and AH content and store result in AL

    添加AL和AH内容并将结果存储在AL中

  8. Store the content of AL in memory location 2051

    将AL的内容存储在内存位置2051中

Program:

程序:

MnemonicsComments
MOV AL, [2050]AL←[2050]
MOV AH, ALAH←AL
MOV CX, 0004CX ← 0004
AND AL, 0FAL ← AL & 0F
ROL AH, CXRotate AH content left by 4 bits(value of CX)
AND AH, 0FAH ← AH & 0F
ADD AL, AHAL←AL+AH
MOV [2051], AL[2051]←AL
HLTStop 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

说明

  1. MOV AL, [2050]: loads contents of memory location 2050 in AL

    MOV AL,[2050] :将存储位置2050中的内容加载到AL中

  2. MOV AH, AL: copy content of register AL to register AH

    MOV AH,AL :将寄存器AL的内容复制到寄存器AH

  3. MOV CX, 0004: assign 0004 to CX register pair

    MOV CX,0004 :将0004分配给CX寄存器对

  4. AND AL, 0F: does AND operation on content of AL with 0F and store result in AL

    AND AL,0F :对具有0F的AL的内容执行AND运算并将结果存储在AL中

  5. 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寄存器对的值

  6. AND AH, 0F: does AND operation on content of AH with 0F and store result in AH

    AND AH,0F :用0F对AH的内容执行AND运算并将结果存储在AH中

  7. ADD AL, AH: add AL and AH content and store result in AL

    添加AL,AH :添加AL和AH内容并将结果存储在AL中

  8. MOV [2051], AL: stores the content of AL in 2051 memory address

    MOV [2051],AL :将AL的内容存储在2051存储器地址中

  9. 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

数字和数字根的总和

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值