题目3、
设BUF DW 123,0,-100,-50,+300
以十进制形式依次输出BUF中的各个数。(对于负数,要输出负号)
代码:
data segment
buf dw 123,0,-100,-50,+300
num db 0ah
mess1 db ',$'
mess2 db '-$'
data ends
stack segment
stack ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax
mov bx,0
mov cx,5
a:
mov dx,0
mov ax,buf[bx]
cmp ax,0
jl d
b:
div [num+0]
add ah,30h
mov dl,ah
mov dh,0
push dx
mov ah,0
cmp ax,0
jne b
c:
pop dx
mov ah,2
int 21h
cmp sp,0
jne c
lea dx,mess1
mov ah,9
int 21h
inc bx
inc bx
loop a
mov ah,4ch
int 21h
d:
lea dx,mess2
mov ah,9
int 21h
mov dx,0
mov ax,buf[bx]
sub dx,ax
mov ax,dx
jmp b
code ends
end start
运行截图: