加入收藏 | 设为首页 | 会员中心 | 我要投稿 东营站长网 (https://www.0546zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 系统 > 正文

Windows / DOS程序集 – 简单数学

发布时间:2021-02-20 23:44:56 所属栏目:系统 来源:网络整理
导读:我目前正在学习 Windows / DOS程序集.我只是制作了一个小程序,它添加了两个基数为10的整数,并将解决方案输出到标准输出.这是我目前的代码: org 100hMOV al,5ADD al,3mov dx,almov ah,9int 21hret 我很困惑为什么在编译时,我得到错误: 错误:操作码和操作数

我目前正在学习 Windows / DOS程序集.我只是制作了一个小程序,它添加了两个基数为10的整数,并将解决方案输出到标准输出.这是我目前的代码:

org 100h


MOV al,5
ADD al,3

mov dx,al

mov ah,9
int 21h

ret

我很困惑为什么在编译时,我得到错误:

错误:操作码和操作数的无效组合

因为从理论上讲,我所做的只是将5放入AL寄存器中,向其中加3,将AL寄存器的内容放入DX寄存器进行输出,然后显示.

任何帮助将不胜感激,谢谢!

解决方法

DX是一个16位寄存器,但AL是一个8位.

将AL加载到DL中,并将DH设置为0.

但那不会做你想要的; function 9 [显示以null结尾的字符串].你告诉它显示一个从数据段的偏移量9开始的字符串,这可能是垃圾.

您需要先将答案转换为一系列数字,然后调用函数9.

有一些示例代码可用于converting the contents of a register to a string.复制到此处以供参考,由用户使用别名Bitdog编写.

; ------ WDDD = Write a Decimal Digit Dword at the cursor & a CRLF ------
;
; Call with,DX:AX = Dword value to print
; Returns,CF set on error,if DX:AX > 655359 max#
;       (see WDECEAX.inc for larger number prints)
align 16
WDDD:   CMP DX,10
    JB  WDDDok
    STC     ;CF=set
    RET     ;error DX:AX exceeded max value
WDDDok: PUSH    AX
    PUSH    BX
    PUSH    CX
    PUSH    DX
    XOR CX,CX   ; clear count register for push count
    MOV BX,10
WDDDnz: DIV BX  ; divide DX:AX by BX=10
    PUSH    DX  ; put least siginificant number (remainder) on stack
    XOR DX,DX   ; clear remainder reciever for next divide
    OR  AX,AX   ; check to see if AX=number is divided to 0 yet
    LOOPNE  WDDDnz  ; get another digit? count the pushes
    MOV AH,2    ; function 2  for interupt 21h write digit
    NEG CX  ; two's compliment,reverse CX
    MOV BL,48   ; '0'
WDDDwr: POP DX  ; get digit to print,last pushed=most significant
    ADD DL,BL   ; convert remainder to ASCII character
    INT 21h ; print ascii interupt 21h ( function 2 in AH )
    LOOP    WDDDwr  ; deincrement CX,write another,if CX=0 we done
    MOV DL,13   ; CR carriage return (AH=2 still)
    INT 21h
    MOV DL,10   ; LF line feed
    INT 21h
    POP DX
    POP CX
    POP BX
    POP AX
    CLC     ;CF=clear,sucess
    RET

; A divide error occurs if DX has any value
; when DIV trys to put the remainder into it
; after the DIVide is completed.
; So,DX:AX can be a larger number if the divisor is a larger number.

(编辑:东营站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读