# CSE 322 Lab 2

February 12, 2018

#### Problem#1

Write an assembly code to print 2 different string that will be stored in 2 different variable.

//Solution

```.MODEL SMALL
.STACK 100H
.DATA ;
CR EQU 0DH ;
LF EQU 0AH ;

MSG db 'Hello',' ', 'Wrold \$'
MSG2 db cr, lf,'This is NEUB\$'

.CODE ;
MAIN PROC ;MAIN PROCEDURE ; CODE SEGMENT
MOV AX,@DATA ;
MOV DS, AX ;

LEA DX, MSG ;Print hello
mov ah,9
int 21h
LEA DX, MSG2 ;Print hello
mov ah,9
int 21h

MOV AH, 4CH ;Exit code
INT 21H
MAIN ENDP

END MAIN```

#### Problem#2

Write an assembly code to take 3 input and print them right away.

//Solution

```mov ah, 1 ;Take input ascii code
int 21h

mov ah, 2 ;Print the ascii code
mov dl, al
int 21h

mov ah, 2 ;Print newline
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h

mov ah, 1 ;Take input ascii code
int 21h

mov ah, 2 ;Print the ascii code
mov dl, al
int 21h

mov ah, 2 ;Print newline
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h

mov ah, 1 ;Take input ascii code
int 21h

mov ah, 2 ;Print the ascii code
mov dl, al
int 21h

```

#### Problem#3

Write an assembly code to take 4 inputs and print them after taking all the inputs.

example

a b c d <– 4 inputs taken
abcd <– Prints

```//Solution

mov ah, 1
int 21h
mov bh, al

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

mov ah, 1
int 21h
mov cl, al

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

mov ah, 1
int 21h
mov bl, al

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

mov ah, 1
int 21h
mov ch, al

mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h

mov dl, bh
int 21h
mov dl, cl
int 21h
mov dl, bl
int 21h
mov dl, ch
int 21h```

#### Problem #4

Write a program to (a) prompt the user, (b) read first, middle, and last initials of a person’s name, and (c) display them duwn the left margin.
Sample execution:

ENTER THREE INITIALS: JFK
J
F
K

//SOlution

```.MODEL SMALL
.STACK 100H
.DATA ;
CR EQU 0DH ;
LF EQU 0AH ;
A DB ? ; DATA SEGMENT
B DB ? ;
C DB ? ;

intro db 'Marut Chapter 4 problem 9. This program will Show three initials you type in vertical allignment\$'
MSG db CR, LF, 'Enter Three initials: \$'

.CODE ;

MAIN PROC ;MAIN PROCEDURE ; CODE SEGMENT
MOV AX,@DATA ;
MOV DS, AX ;

LEA DX, intro
MOV ah,9
INT 21h

top:

LEA DX, MSG
MOV ah,9
INT 21h

MOV AH,1 ;First Initial
INT 21h
MOV A,AL

MOV AH,1 ;SECOND Initial
INT 21h
MOV B,AL

MOV AH,1 ;THIRD Initial
INT 21h
MOV C,AL

mov ah , 02 ; New line
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h

MOV DL, A
INT 21H

mov ah , 02 ; New line
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h

MOV DL,B
INT 21H

mov ah , 02 ; New line
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h

MOV DL,C
INT 21H

jmp top

MOV AH, 4CH ;Exit code
INT 21H
MAIN ENDP

END MAIN```

#### Problem #5

Write a program to (a) display a “?”, (b) read two decimal digits whose sum is less than 10, (c) display them and their sum on the next line, with an appropriate message.

Sample execution:
?27
THE SUM OF 2 AND 7 IS 9

//Solution