Skip to content

Instantly share code, notes, and snippets.

@chunrapeepat
Created March 11, 2019 16:24
Show Gist options
  • Save chunrapeepat/23bec1128969f61a3713b8ed858dd239 to your computer and use it in GitHub Desktop.
Save chunrapeepat/23bec1128969f61a3713b8ed858dd239 to your computer and use it in GitHub Desktop.
Print the number in Assembly Language (printnum.asm)
TITLE print the number
STACK SEGMENT STACK
dw 64 dup(?)
STACK ENDS
DATA SEGMENT
LINE db 3 dup(?),10,13,'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:STACK
FIRST PROC
mov ax,DATA
mov ds,ax
; Print the A number
mov ax,-23
call PRINT
mov ah,4ch
int 21h
FIRST ENDP
PRINT PROC
mov dl,10
push ax
; Fill the line with space
mov cx,3
lea bx,LINE
FILL:
mov byte ptr [bx],' '
inc bx
loop FILL
; Check is negative
cmp ax,0
jge NEXT
neg ax
; Convert Number to ASCII
NEXT:
cbw
div dl
dec bx
add ah,'0'
mov [bx],ah
cmp al,0
jne NEXT
; Check Is Negative
pop ax
cmp ax,0
jge DISPLAY
dec bx
mov byte ptr [bx],'-'
; Print the number
DISPLAY:
mov ah,9
lea dx,LINE
int 21h
ret
PRINT ENDP
CODE ENDS
END FIRST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment