Case Study

Tuesday, October 6, 2015

Basic ASM Code for Input/ Output Operation

.model small
.stack 100h
.data
prompt  db  'Enter your name (7 Chars Max):$'
greet   db  "Hello $"
nam     db  8 dup(?) ; 7 plus term char $
Ast     db  "*$"
crlf    db  13, 10, 24H
.code
main   proc
mov     ax, seg prompt
mov     ds,ax

Start:
; Display Name prompt ; lea (load effective address)
lea     dx, prompt
mov     ah, 9
int     21h

mov     cx, 7   ; get 7 chars
lea     si, nam ; buffer to hold name
lea     dx, Ast ; display *

balik:
; get char typed
mov     ah, 7
int     21h
; save in our buffer, current pos in si
mov     byte ptr[si], al

; Display Asterick
; Asterick already in dx
mov     ah, 9
int     21h

; increase our buffer pointer
inc     si

; No need for the "slow" loop instruction
dec     cx
jnz     balik ; jump if not zero

; properly terminate our string
mov     byte ptr[si], "$"

; insert blank line
lea     dx, crlf
mov     ah, 9
int     21h

; display hello
lea     dx, greet
mov     ah, 9
int     21h

; Now display entered name
lea     dx, nam
; outputs the input
mov     ah, 9
int     21h

; exit
mov     ah, 4ch
int     21h
main   endp
end main

No comments:

Post a Comment