Digital System Engineering
Digital System Engineering
EE 390
Digital Systems Engineering
Experiment No.2
Submitted By:
Razan Farrj Al-Anazi
ID: 2211005101
Introduction:
Objectives:
Exercise 1:
Write, assemble, and run a program calculate sum and average of 5 bytes of data
And saves the result. The data should be the following hex numbers: 25H, 12H,
15H, 1FH, and 2BH. Use the simplified segment definition model.
The code
org 100h
.DATA
DATA DW 234DH.1DE6H.3BC7H.566AH
RESULT DW DUP<8>
.CODE
MOU AX.EDATA
MOU DS AX
LEA SI DATA
MOU AX. [SI]
MOU CX.3
NEXT:
ADD SI.2
ADD AX. [81]
LOOP NEXT
MOU RESULT.AX
HLT
ret
Exercise 2:
Assume that there is a class of five students with the following grades: 69, 87, 96,
45, and 75. Write and run an assembly program to find the highest grade and
Save it in certain memory location.
The code
.model small
.stack 100h
.data
grades db 69, 87, 96, 45, 75
num_students equ ($ - grades)
highest_grade db 0
.code
main proc
mov ax, @data
mov ds, ax
update_highest:
mov highest_grade, al
jmp continue_loop
done:
; Save the highest grade in memory location "highest_grade"
mov di, offset highest_grade
mov al, highest_grade
mov [di], al
The code
model small.
stack 100h.
data.
grades db 69, 87, 96, 45, 75
num_students equ ($ - grades)
code.
main proc
mov ax, @data
mov ds, ax
:update_lowest
mov lowest_grade, al
jmp continue_loop
:done
"Save the lowest grade in memory location "lowest_grade ;
mov di, offset lowest_grade
mov al, lowest_grade
mov [di], al
2. What is the difference between the source file and the object file? Which
program converts Between them?
A source file is a text file containing the program written in a high-level
programming language or assembly language. It contains the human-readable
code that the programmer writes. An object file, on the other hand, is a file
generated by the assembler or compiler that contains machine code instructions
and data in a format that can be directly loaded into memory and executed by
the computer. The program that converts between them is called an assembler
or a compiler depending on whether the source language is assembly or a high-
level language.
The linker program is responsible for combining multiple object files and
libraries into a single executable file. It resolves references between different
modules, ensuring that all symbols (functions and variables) are properly linked
and addresses are correctly resolved. The linker also performs memory
allocation for the final executable, arranging the code and data in memory in a
way that can be executed by the operating system.
4- Find the errors in the following assembly program and re-write it correctly
as Simplified Segment Format.
The errors in the provided assembly program include incorrect segment directives
and missing segment declarations.
Corrected program in Simplified Segment Format (SSF):
.MODEL SMALL
.DATA
X1 DB ?
X2 DB 30H
.CODE
MOV AX, @DATA
MOV DS, AX
.EXIT
END
5. Write an assembly program that adds four words of data and save the
result in memory. Assume the values are: 234DH, 1DE6H, 3BC7H, and
566AH. Use the simplified segment Definition model.
. .MODEL SMALL
.DATA
NUMS DW 234DH, 1DE6H, 3BC7H, 566AH
RESULT DW ?
.CODE
MOV AX, @DATA
MOV DS, AX
ADD_LOOP:
MOV AX, [BX] ; Load the next word into AX
ADD DX, AX ; Add AX to sum in DX
ADD BX, 2 ; Move to next word
LOOP ADD_LOOP ; Repeat for all words
.EXIT
END
6. Assume that there is a class of ten students with the following grades: 77,
46, 50, 36, 56, 68, 40, 63, 70, 29. Write a program to find the number of
passed students and save the result in Memory. Use the simplified segment
definition model.
.MODEL SMALL
.DATA
GRADES DB 77, 46, 50, 36, 56, 68, 40, 63, 70, 29
NUM_STUDENTS DB 10
NUM_PASSED DB ?
.CODE
MOV AX, @DATA
MOV DS, AX
COUNT_PASSED:
MOV AL, [SI] ; Load the grade
CMP AL, 50 ; Compare with passing grade
JAE IS_PASSED ; Jump if grade is greater than or equal to 50
JMP NOT_PASSED
IS_PASSED:
INC BL ; Increment counter for passed students
NOT_PASSED:
INC SI ; Move to the next grade
LOOP COUNT_PASSED ; Repeat for all students
The difference between the two instructions is the value that is loaded into the
`BX` register:
1. `MOV BX, DATA1`: This instruction moves the value stored at the memory
address labeled `DATA1` into the `BX` register. It treats `DATA1` as a
memory operand, so the value loaded into `BX` is the content of the memory
location labeled `DATA1`.
2. `MOV BX, OFFSET DATA1`: This instruction moves the offset of the memory
address labeled `DATA1` into the `BX` register. It does not access the content
of `DATA1`, but rather the location or address where `DATA1` is stored in
memory. This is useful when you want to get the address of a variable or label
for use in addressing calculations, such as accessing elements of an array or
jumping to a label in the code.
8. How many bytes are defined by the following pseudo instruction? DATA1
DB 6 DUP (4 DUP(0FFH))
- `4 DUP (0FFH)` defines an array of 4 bytes, each initialized to `0FFH`. So, this
part defines 4 bytes.
- `6 DUP (4 DUP(0FFH))` defines an array of 6 elements, each element being the
array defined in the previous step. So, this part defines 6 * 4 = 24 bytes.
Therefore, the total number of bytes defined by `DATA1 DB 6 DUP (4
DUP(0FFH))` is 24 bytes.
Conclusion
This lab experiment focused on learning the basics of writing,
translated into machine code for execution, while pseudo instructions are