Lab Session 3
Lab Session 3
Lab Questions
.model small:
Memory Model: The .model small directive specifies a "small" memory model for the program. This
means that both code (instructions) and data (variables) will fit within a single segment each.
Segment Usage: In the small model, only two segments are used:
o Code Segment (CS): Stores all executable code (procedures, loops, etc.).
o Data Segment (DS): Stores all global data (variables).
Addressing: Using a single segment for code and a single segment for data makes addressing simpler but
limits the total size of each segment. In real mode, each segment can only be 64KB in size, so a .model
small program can only have up to 64KB of code and 64KB of data.
Typical Use: The small model is ideal for simpler programs that don’t need large amounts of code or data.
.stack 100h:
Stack Definition: The .stack 100h directive sets up a stack segment in memory and allocates 256 bytes
(100h in hexadecimal) for the stack.
Purpose of the Stack: The stack is a Last In, First Out (LIFO) structure used to store temporary data like
function return addresses, register values during subroutine calls, and local variables.
Size: Here, 100h (or 256 bytes) is typically enough for small programs. If the program has many nested
calls or requires more temporary storage, a larger stack size might be necessary.
Location in Memory: When .stack is declared, the assembler sets aside the specified amount of memory
at the start of the program's stack segment, ensuring that there is reserved space for stack operations.
o How does the program convert ASCII to numeric values and vice versa?
Answer:
Converting ASCII to Numeric Value
When the user inputs a digit from 0 to 9, the ASCII code for that digit is stored in the AL
register. ASCII codes for digits start at 30h (48 in decimal) for '0' and go up to 39h (57 in
decimal) for '9'. To convert this ASCII code to its corresponding numeric value, we
subtract 30h (or 48 decimal).
Converting Numeric Value Back to ASCII
To display the result, the numeric value needs to be converted back to an ASCII character,
as int 21h requires ASCII codes for display purposes. To convert a numeric value (0–9)
back to ASCII, we add 30h (or 48 in decimal) to it.
o What is the purpose of mov ah, 01h and mov ah, 02h?
Answer:
mov ah, 01h (Input function): Reads a character from the keyboard and places it in
AL.
mov ah, 02h (Output function): Displays the character in DL on the screen.
o Explain the difference between mov dl, 10 and mov dl, 13.
Answer:
1. mov dl, 10: Newline (Line Feed)
10 in decimal (or 0Ah in hexadecimal) represents the newline (line feed) character in
ASCII. When this character is printed, it moves the cursor down to the next line but does
not return it to the beginning of the line.
This instruction creates a new line on the screen, moving the cursor vertically.
2. mov dl, 13: Carriage Return
13 in decimal (or 0Dh in hexadecimal) represents the carriage return character in ASCII.
When this character is printed, it returns the cursor to the beginning of the current line
without moving it down to the next line.
This instruction resets the cursor’s position to the start of the line, typically used in
conjunction with the newline to start a new line from the beginning.
o Write a short note on the importance of register usage in assembly language
programming.
Answer:
In assembly language programming, registers play a critical role in executing
instructions efficiently and managing data within the CPU. Registers are small, fast
storage locations directly within the processor, which can quickly hold and manipulate
data without needing to access slower memory locations. Here are some key points
highlighting the importance of registers in assembly language:
Speed and Efficiency: Registers enable the CPU to access and process data
much faster than accessing memory, making programs run more efficiently.
Since instructions using registers execute faster than those involving memory,
optimizing register usage can significantly improve performance.
.CODE
MAIN PROC
mov dx , offset RANGE ;for printing string
mov AH,9
int 21h
mov AH,1
int 21h
mov AH,0
mov R,AX
SUB R,48
mov CX,R
L:
PUSH CX
NEXT:
MOV BX ,N
ADD SUM,BX
POP CX
LOOP L
LEA DX,UN
mov AH,9
int 21h
;output code
mov AX,SUM ;AX=N=>25
L1:
div bx ;divide => AX=AX/BX =25/10
;incase of 8bit reg => AL=quotient , AH = remainder
;incase of 16bit reg => AX=quotient , DX = remainder
;AX =2, DX=5
push dx ;5 save in stack
mov dx,0 ;DX =0
mov ah,0 ;AX AH 00000000 AL=quotient
inc cx
cmp ax,0 ;(2==0)
jne L1 ;jump not equal => (AX !=0)
mov ah,2 ;output character
L2:
pop dx ;first time pop 2 and second time pop 5 =25
add dx,48
int 21h
loop L2
ret
OUTPUT:
Constraint:
Can only take 4 digits.
include 'emu8086.inc'
.model small
.stack 100h
.CODE
_MainProc PROC
sub al, 48
mov bl, al
mov dl, 10
mov ah, 02h
int 21h
mov dl, 13
mov ah, 02h
int 21h
sub al, 48
sub bl, al
add bl, 48
mov dl, 10
mov ah, 02h
int 21h
mov dl, 13
mov ah, 02h
int 21h
mov dl, bl
mov ah, 02h
int 21h
_MainProc ENDP
END
Multiplication:
include 'emu8086.inc'
.model small
.stack 100h
.CODE
_MainProc PROC
mov dl, 13
mov ah, 02h
int 21h
sub al, 48
mul bl
add al, 48
mov bl,al
mov dl, 10
mov ah, 02h
int 21h
mov dl, 13
mov ah, 02h
int 21h
_MainProc ENDP
END
Division:
Criteria Excellent (5) Good (4) Satisfactory (3) Needs Improvement (2) Unsatisfactory (1) Marks
Algorithm is mostly
Designs a well-structured
efficient with clear Algorithm is functional Algorithm is incomplete
and efficient algorithm,
Algorithm Design & Logic logic but has some but lacks clarity, or has significant flaws No meaningful algorithm
with clear logic flow and
Flow inefficiencies or minor optimization, or proper in logic and instruction or logic is provided.
correct use of assembly
errors in instruction flow in parts of the code. usage.
instructions.
usage.
Implements the assembly
program correctly with no
Implements the Multiple syntax errors or
syntax errors, Program is functional but
program with minor misuse of instructions and Program is incomplete
demonstrating contains several syntax
Code Implementation & Syntax syntax errors that do addressing modes affect or filled with errors,
complete understanding of errors or improper use of
not affect overall the program’s making it non-functional.
registers, memory registers and addressing.
functionality. functionality.
addressing, and assembly
instructions.