Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;read a number in decimal, convert it to hex and print it on the fuckin screen
- assume cs:code, ds: data
- data segment
- nrten db 10,10 dup(?)
- lten db ?
- nr dw ? ; the number in base ten
- temp dw ?
- invhex db 10 dup (?)
- hextable db "0123456789ABCDEF"
- result db 10 dup (?)
- newline db 10,13,'$'
- data ends
- code segment
- start:
- mov ax,data
- mov ds,ax
- ;read the number in decimal
- mov ah,0Ah
- mov dx,offset nrten
- int 21h
- mov al, nrten[1]
- mov lten,al
- ;mov si,lten
- ;mov nrten[si+1],'$'
- mov cl, lten ;move the length of the string in cx
- mov ch,0
- mov temp,1
- dec cx
- mulme:
- ; multiply temp with 10
- mov ax,temp
- mov dx,10
- mul dx ; ax := temp * 10
- mov temp,ax
- loop mulme
- ;now we have the power of then corresponding to the length of the string
- mov si,2
- mov nr,0
- mov cl, lten ;move the length of the string in cx
- mov ch,0
- repme:
- sub nrten[si],'0'
- mov ax,temp ; temp can be 1,10,100 ... whatever
- mul nrten[si] ; ax := nrten[si] * ax
- add nr,ax ;add the new digit to the number
- ; divide temp with 10
- mov ax,temp
- mov dl,10
- div dl ; al := temp / 10
- mov temp,ax
- inc si
- loop repme
- ;we should have the number in nr
- ;convert the bitch to hexa
- mov si,0
- convertme:
- mov ax,nr
- mov dl,16
- div dl ; al := nr / 16 ah = nr mod 16
- mov dl,al ; store the quotient, we will need it
- lea bx,hextable
- mov al,ah
- xlat
- ;al now has the ASCII hex digit
- ;we put it in a string (we'll invert it later)
- mov invhex[si],al
- inc si
- ;we still have the quotient in dl
- ;we overwrite the number with it
- mov dh,0
- mov nr,dx
- cmp nr,0
- jne convertme
- ;now invert the invhex string and get this over with
- ;we have it's length in si
- dec si
- mov cx,si
- inc cx; si goes from 0
- mov di,0
- invertme:
- mov al,invhex[si]
- mov result[di],al
- dec si
- inc di
- loop invertme
- mov result[di],'$'
- ;print newline
- mov ah,09h
- lea dx, newline
- int 21h
- ;print it on the screen
- mov ah,09h
- lea dx, result
- int 21h
- ;wait for keyboard
- mov ah,1h
- int 21h
- mov ax,4C00h
- int 21h
- code ends
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement