彙編實現10進位制轉16進位制並以ASCII碼輸出

孤落時辰·發表於2020-11-22

彙編實現10進位制轉為16進位制

stkseg segment para stack ‘stack’
dw 32h dup(?)
stkseg ends

data segment
buf1 db 4 dup(?)
data ends

code segment ‘code’
assume ss:stkseg,cs:code,ds:data
start:mov ax,data
mov ds,ax

  mov al,0
  call input
  call zhuan

  mov ah,4ch
  int 21h

input proc near
mov bx,0
mov cx,10
one: mov ah,01h
int 21h

  sub al,30h
  cmp al,0
  jl finish
  cmp al,9
  jg finish
  cbw
  xchg ax,bx
  mul cx
  add bx,ax
  jmp one

finish:
ret
input endp

zhuan proc near
mov cx,16
mov ax,bx
mov si,0
again:div cx
cmp dl,9
jle one
add dl,7h
one: add dl,30h
mov buf1[si],dl
inc si
mov dx,0
cmp ax,0
jg again
ret
zhuan endp

code ends
end start

相關文章