Lab_2
Lab_2
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
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:
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
exit
main ENDP
END main
Task:
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
exit
main ENDP
END main
Task:
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