Case Study

Wednesday, October 7, 2015

Midterm Exam For 4th Year Students, Due 10/8/2015

create a simple ASM program that will allow user
to select a choices available
and display a correspoding text display
upon successful selection of choice

Example:

Menu
1. ORder
2. Exit
Enter Choice:__

If Choice is 1, Display a text "You chose Ordering Function";
If Choice is 2, Display a text "You chose to exit";

ASM code for using Addition in Arithmetic / Logical Instruction Set

.model small
.stack 100h
.data
message db "Enter a Number $"
message2 db "Enter 2nd Number $"
message3 db " +  $"
message4 db " = $"
.code
main proc
mov ax,seg message
mov ds,ax
mov dx,offset message
mov ah,9h
int 21h

mov ah, 1h ;store input in al
int 21h

mov bl,al

mov ax,seg message2
mov ds,ax
mov dx,offset message2
mov ah,9h
int 21h

mov ah, 1h ;store input in al
int 21h

mov cl,al

mov dl,bl
mov ah,2h
int 21h

mov ax,seg message3
mov ds,ax
mov dx,offset message3
mov ah,9h
int 21h

mov dl,cl
mov ah,2h
int 21h

mov ax,seg message4
mov ds,ax
mov dx,offset message4
mov ah,9h
int 21h

sub bl,30h  ;converts to decimal
sub cl,30h

add bl,cl
add bl,30h

mov dl,bl     ;prints character
mov ah,2h
int 21h

mov ah, 4ch
int 21h

endp
end main

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