汇编语言 emu8086

2025-03-01 06:38:55
推荐回答(1个)
回答1:


; 不好意思,上次回答的问题好像也是你提的吧,当时把第4题的答案贴成第3题的了。后来才发现
data segment
    errmsg db 0dh,0ah,'Your input number is invalid.',0dh,0ah,'$'
    sqmsg db 0dh,0ah,'square number is :$'
    inmsg db 'Input your number(0-9):$'
data ends

code segment
    assume cs:code, ds:data
start:
; set segment registers:
    mov ax, data
    mov ds, ax

rpt:
    lea dx,inmsg ;
    mov ah,9     ;show inmsg string
    int 21h      ;

    mov ah,1     ;read a number
    int 21h      ; 21h中断的1子功能

    cmp al,'0'
    jb err
    cmp al,'9'
    ja err

    and al,0Fh  ;ascii -> real value
    mov ah,0    ;eg: 字符5的ASCII值是35H,and 0fh之后,变成5,就是我们想要的结果。
    mov bl,al   ;为al * bl作准备
    mul bl      ;calculate x*x, 结果放在AX中

    mov cx,ax   ;save result in ax
    lea dx,sqmsg
    mov ah,9    ;show information string
    int 21h

    mov ax,cx
    call print  ;show result on screen
    jmp exit
err:
    lea dx,errmsg
    mov ah,9      ;show error message
    int 21h
    jmp rpt
    
exit:
    mov ax, 4c00h ; exit to operating system.
    int 21h    

;print the value in ax with base 10
print proc near
    mov bx,10  ; base 10
    xor cx,cx  ;cx set 0
Q0:
    xor dx,dx
    div bx
    xor dx,0e30h   ;为调用10H中断的0e功能作准备,
    push dx        ;10H中断,ah=0eh, al=要显示的字符
    inc cx         ;计数
    cmp ax,0       ;商不为0,说明没有除尽
    jnz Q0
Q1:
    pop ax
    int 10h
    loop Q1
    ret
print endp
code ends
end start ; set entry point and stop the assembler.

至于第2题,我上次回答你的结果是对的吧,为什么再问一遍?