0% found this document useful (0 votes)
6 views

Lab_2

Lab 2 of the CSC-221 course focuses on memory manipulation and 8-bit addition using assembly language. It covers data types, memory allocation, and arithmetic operations, providing exercises to practice loading, storing, and modifying data in memory. The lab includes tasks to assemble and debug code, as well as questions to reinforce understanding of the concepts learned.

Uploaded by

haxansaleem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lab_2

Lab 2 of the CSC-221 course focuses on memory manipulation and 8-bit addition using assembly language. It covers data types, memory allocation, and arithmetic operations, providing exercises to practice loading, storing, and modifying data in memory. The lab includes tasks to assemble and debug code, as well as questions to reinforce understanding of the concepts learned.

Uploaded by

haxansaleem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CSC-221 Lab Manual Lab 2: Memory Manipulation and 8-bit Addition

Lab 2: Memory Manipulation and 8-bit Addition

Lab Objective:
This lab focuses on memory manipulation and performing 8-bit addition in assembly
language. You will learn how to allocate memory, load and store data in memory,
perform arithmetic operations on 8-bit numbers, and store the results back into
memory.

1. Data Types:
MASM defines various intrinsic data types, each of which describes a set of values
that can be assigned to variables and expressions of the given type. The following
table lists these data types. The first 9 data types are used to define integer data, while
the last 3 are used to define real data according to the IEEE standard real number
formats.

Prepared by: Asad Ullah Khan Iqra University H-9 Campus Islamabad
CSC-221 Lab Manual Lab 2: Memory Manipulation and 8-bit Addition

Data definition has the following syntax:


[name] directive initializer [,initializer] . . .
For more information, refer to your textbook or class notes.

2. Memory Allocation and Data Storage:


Learn how to allocate memory using the .DATA segment and store 8-bit values.

Exercise Code 1:

The following program demonstrates integer data definition under the .DATA
section. You may open and view this program in any text editor. Assemble and link
this program to produce the IntegerDef.exe executable file.
TITLE Integer Data Definitions (File:IntegerDef.asm)
; Examples Demonstrating Integer Data Definition
.686
.MODEL flat, stdcall
.STACK
INCLUDE Irvine32.inc
.data
; Byte Values
byte1 BYTE 'A' ; 'A' = 65 = 41h
byte2 BYTE 0 ; smallest unsigned byte value
byte3 BYTE 255 ; largest unsigned byte value
byte4 SBYTE -128 ; smallest signed byte value
byte5 SBYTE +127 ; largest signed byte value ;
byte6 BYTE ? ; uninitialized
; Word Values
word1 WORD 65535 ; largest unsigned word value
word2 SWORD -32768 ; smallest signed word value
word3 WORD ? ; uninitialized
; DoubleWord Values
dword1 DWORD 0FFFFFFFFh ; largest unsigned value in hex
dword2 SDWORD -2147483648 ; smallest signed value in decimal
; QuadWord Value
quad1 QWORD 0123456789ABCDEFh
.code
main PROC

Prepared by: Asad Ullah Khan Iqra University H-9 Campus Islamabad
CSC-221 Lab Manual Lab 2: Memory Manipulation and 8-bit Addition

; No instructions to execute
exit
main ENDP
END main

Task:

– Assemble and link the code using make32.


– Use a debugger (windbg –QY –G filename.exe) to examine the memory
locations of num1, num2, and result and observe the stored values.
– Modify the initial values of num1 and num2 and observe the changes in memory.
– Fill in the following table showing the Location (address) of these variables in
the data segment in memory, as well as their values in hex and in decimal.
Observe that the variables occupy locations at successive addresses in memory,
according to their

Exercise Code 2:
TITLE Add and Subtract (memoryallocation.asm)
; This program loads values into registers
.686
.MODEL flat, stdcall

Prepared by: Asad Ullah Khan Iqra University H-9 Campus Islamabad
CSC-221 Lab Manual Lab 2: Memory Manipulation and 8-bit Addition

.STACK
INCLUDE Irvine32.inc
.DATA
num1 BYTE 10h ; Allocate a byte and initialize with 10h
num2 BYE 20h ; Allocate a byte and initialize with 20h
result BYTE ? ; Allocate a byte for the result
.code
main PROC

MOV AL, num1 ; Load num1 into AL


MOV BL, num2 ; Load num2 into BL

exit
main ENDP
END main

Task:

– Assemble and link the code using make32.


– Use a debugger (windbg –QY –G filename.exe) to examine the memory
locations of num1, num2, and result and observe the stored values.
– Modify the initial values of num1 and num2 and observe the changes in
memory.

3. 8-bit Addition and Result Storage:


Learn how to add two 8-bit numbers and store the result in memory.

Exercise Code 1:
TITLE Add and Subtract (memoryallocation.asm)
; This program loads values into registers
.686
.MODEL flat, stdcall
.STACK
INCLUDE Irvine32.inc
.DATA
num1 BYTE 10h ; Allocate a byte and initialize with 10h
num2 BYE 20h ; Allocate a byte and initialize with 20h
result BYTE ? ; Allocate a byte for the result
.code
main PROC

Prepared by: Asad Ullah Khan Iqra University H-9 Campus Islamabad
CSC-221 Lab Manual Lab 2: Memory Manipulation and 8-bit Addition

MOV AL, num1 ; Load num1 into AL


ADD AL, num2 ; Add num2 to AL
MOV result, AL ; Store the result in memory (result)

exit
main ENDP
END main

Task:

– Assemble, link, and run the code.


– Use a debugger to observe the value stored in result after the addition.
– Modify the initial values of num1 and num2 and observe the changes in
result.
– Experiment with different addition operations and observe the results.

Lab Questions:
Q#1. Explain the purpose of the .DATA segment.
Q#2. How do you access the value of a memory location in assembly language?
Q#3. What happens if the result of an 8-bit addition exceeds 255?
Q#4. How would you store the result of an 8-bit addition in a 16-bit register?
Q#5. Write a data declaration for an 8-bit unsigned integer variable.
Q#6. Write a data declaration for a 32-bit signed integer variable.
Q#7. Declare a 16-bit signed integer and initialize it with the smallest negative 16-
bit number.
Q#8. Declare an unsigned 16-bit integer variable wArray that uses three initializers.
Q#9. Declare an uninitialized array of 50 unsigned 32-bit integers named dArray.
(Hint: Check DUP operator)

Prepared by: Asad Ullah Khan Iqra University H-9 Campus Islamabad

You might also like