汇编 两个有符号数相加 ...求救啊

汇编 两个有符号数相加 ...求救啊,第1张

DSEG SEGMENT

数据段:在此处添加程序慎仿慎所需的数据

A DB 2,5定义A1和A2

B DB -3,4定义B1和B2

C DW 0定义存放结果的变量

DSEG ENDS

CSEG SEGMENT

assume cs:CSEG, ds:DSEG

MAIN PROC FAR 主程序入口

mov ax, dseg

mov ds, ax

此处添加大迅主程序代码

MOV AL,A

IMUL B

ADD C,AX

MOV AL,A+1

IMUL B+1

ADD C,AX

按任意键退出

mov ah,1

int 21h

mov ax, 4c00h 程序宽敬结束,返回到 *** 作系统系统

int 21h

MAIN ENDP

CSEG ENDS

END MAIN

prog name:calculating with signed byte

date: 08.10.27

author: ivshe

.model small

.data

signed byte ranging from -128 to +127 (including results!!)

datax db -2 (e4H)

datay db 64 (0cH)

errmsg db 0dh,0ah,'Wrong input.Exit.','$'

ofmsg db 0dh,0ah,'Overflow.Exit.','$'

hextable db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h,41h,42h,43h,44h,45h,46h

.code

.startup

input the operator in AL

+=2bH,-=2dH,*=2aH,/=2fH

mov ah,1h

int 21h

judge which operation is selected

cmp al,2bh

je _add

cmp al,2dh

je _sub

cmp al,2ah

je _mul

cmp al,2fh

je _div

mov ah,9h

mov dx,offset errmsg wrong input

int 21h

jmp exit

_add:

mov ax,0h

mov bx,0h

mov al,datax

mov bl,datay

add al,bl

jo _overflow

call disp

jmp exit

_sub:

mov ax,0h

mov bx,0h

mov al,datax

mov bl,datay

sub al,bl

jo _overflow

call disp

jmp exit

_mul:

mov ax,0h

mov bx,0h

mov al,datax

mov bl,datay

imul bl

jo _overflow

call disp

jmp exit

_div:

mov ax,0ff00h 此处有符号扩展

mov bx,0h

mov al,datax

mov bl,datay

idiv bl

call disp

jmp exit

_overflow:

mov dx,offset ofmsg

mov ah,9h

int 21h

jmp exit

disp proc

procedure name:disp

function: display a byte in the form of hex

input: al=byte data

output: n/a

push cx

push bx

mov bx,offset hextable

push ax

mov ah,2h

mov dl,2ch

int 21h 输出逗号

pop ax

mov ah,0h

mov cl,al

shl ax,4

mov al,cl

and al,0fh 将AL的高四位放到AH的第四位,如AL=1101 0010,转换后

AH=0000 1101 , AL=0000 0010

xlat 将al中转换成对应16进制的ascii

mov cl,al

mov al,ah

xlat 将ah中转换成对应16进制的ascii

mov ch,al 此时CX中存储着两位十六进制的ASCII

mov dl,ch

mov ah,2h

int 21h

mov dl,cl

mov ah,2h

int 21h

pop bx

pop cx

ret

disp endp

exit:

mov ax,4c00h

int 21h

end


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12446330.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存