Lab 03
Lab 03
Subject: COAL.
Date: 27-09-2023.
LAB 03: COMMAND PROMPT PROGRAMMING USING DEBUG
Objectives:
1. How to write assembly code on command prompt?
2. Memory manipulation Instructions in debug.
3. How to save a program?
4. How to load the saved program?
5. Practices
Pre-Lab Task
Types of instructions:
1- Data Transfer Instructions
Register to Register
Register to Memory
Memory to Register
Constant to Register
2- Arithmetic Instructions
ADD, SUB, MUL and DIV
3- Logic Instructions
Boolean AND, OR, NOT and XOR
The MUL Instruction
There are two instructions for multiplying binary data. The MUL (Multiply) instruction handles
unsigned data. MUL instructions affect the Carry and Overflow flag.
Syntax
The Syntax for the MUL instructions is as follows −
MUL multiplier
Multiplicand in will be in an accumulator, depending upon the size of the multiplicand and the
multiplier and the generated product is also stored in two registers depending upon the size of the
operands. Following section explains MUL instructions with three different cases
SN Scenarios
1 When two bytes are multiplied -
The multiplicand is in the AL register, and the multiplier is a byte in the memory or in another
register. The product is in AX. High-order 8 bits of the product is stored in AH and the low-order
8 bits are stored in AL.
In-Lab Task:
Debug: M (Move)
Copies the contents of a block of memory to another block of memory.
Syntax
m range address
How to Save Program:
There are three stages to save this program:
Write 'n' and the name of the program like -n first.com Now the interesting point. We should
specify how many bytes will be saved. So, we have to pass a value to CX register. Write r CX
and press enter. And enter the number of bytes you want to save. Practically, write the difference
between where your program starts and where it ends. In this example, 0109-0100=9 bytes. More
practically, look at the last address and take its low byte. It will be sufficient if the high byte of
the address is 01. Finally write 'w' and the program will be saved.
You see, with ' u 'debug shows us the code with op-codes. So for example, we can easily say that
B8 is the operation code of mov ax, The second way of loading a program is using 'l' (load).
We write 'n' and the name of the file which will be loaded. Then we write just ' l '. And the
program is loaded. If it is wanted to see the code, u can be used.
Program Exercise:
Take two values at two different memory locations i.e. 75 & 80, perform following operation on
numbers
ADD, SUB, MUL, DIV.
Show all the individual results at 5 consecutive memory locations starting from 230. Save and
Load the program.
Note: For each operation take 2 different values, first value should always be greater than second
value and divisible.
Post-Lab Assignment:
Translate the high-level language assignment statement A=30+5*A-12/B into assembly code.
Let A and B be byte variables and suppose there is no overflow also save and load program.
Perform following operations and show result,
Multiply 80 h with FFh
Divide 1250h with 7
Solution:
We take different values 75, 80 and store in Ax and Bx respectively then move it to different
location such as 50 and 51 index.
Then add value store in Bx with ax and result is stored in the Ax value then move Ax to 230
locations.
Then perform multiplication in two different values taken and store in Ax and Bx again and
move to different memory location. The final Multiplication result store in 231
Then we choose again two different values stored in AX and Bx register and then perform
Subtraction and the result store in Ax which I move to location 232.
Then Div values which is stored in Ax and take new value which I store in the Cx register and
division result store in 233.
Solution:
First we add two numbers, then multiply that numbers and stored each of them in the memory
and then subtracted and then divide them and stored them in the memory.