;
;simple output
;Please input 8 binary numbers:10000111
;Unsigned Decimal:135
;Signed Decimal:-121
.8086
.model small
.stack
.data
Msg1 db 'Please input 8 binary numbers:$'
Msg2 db 0dh,0ah,'Unsigned Decimal:'
Unsigned db 3 dup(0)
db '$'
Msg3 db 0dh,0ah,'Signed Decimal:'
Sign db ?
Signed db 3 dup(0)
db '$'
.code
.startup
lea dx,Msg1
mov ah,9
int 21h
mov cx,8
mov bl,0
again:
mov ah,1
int 21h
shl bl,1
sub al,30h
or bl,al
loop again
mov bh,0
push bx
call BinToUnsign
lea dx,Msg2
mov ah,9
int 21h
call BinToSign
lea dx,Msg3
mov ah,9
int 21h
.exit 0
BinToUnsign proc
push bp
mov bp,sp
push ax
push cx
mov ax,4[bp]
mov cl,100
div cl
add al,30h
mov Unsigned,al
mov al,ah
mov ah,0
mov cl,10
div cl
add al,30h
mov Unsigned[1],al
add ah,30h
mov Unsigned[2],ah
pop cx
pop ax
pop bp
ret
BinToUnsign endp
BinToSign proc
push bp
mov bp,sp
push ax
push cx
mov ax,4[bp]
test al,10000000b
jz Pos
neg al
mov Sign,'-'
jmp display1
Pos:
mov Sign,'+'
display1:
mov cl,100
div cl
add al,30h
mov Signed,al
mov al,ah
mov ah,0
mov cl,10
div cl
add al,30h
mov Signed[1],al
add ah,30h
mov Signed[2],ah
pop cx
pop ax
pop bp
ret 2
BinToSign endp
end
正在学习汇编,先整些简单的练练手