Namal University Mianwali
Department of Computer Science
Lab Manual
Course CSC-241-L Computer Organization and Assembly
Language
Instructor Muzamil Ahmed Session / 2023-2027 (3rd)
Semester
Lecture # 03
Topic Accessing and Manipulating Data in Registers and
Memory
Objective To understand how data is stored in registers and
memory.
To learn techniques for accessing, moving, and
manipulating data in assembly language using
registers and memory locations.
To develop the ability to write assembly programs for
basic data operations such as addition, subtraction,
and logical operations
Task 1: Develop two assembly language programs based on the provided
source codes, ensuring they display register values and match output values
with corresponding comments, and document your observations.
OBJECTIVES:
Zero and Sign Extension: The code demonstrates the use of MOVZX and MOVSX instructions
to extend smaller data types (e.g., bytes and words) into larger registers, with MOVZX for zero
extension and MOVSX for sign extension.
Memory Access: The code accesses and manipulates values stored in memory, including
direct-offset addressing of byte, word, and doubleword arrays (arrayB, arrayW, arrayD).
Data Exchange: The XCHG instruction is used to exchange data between memory and
registers, specifically swapping the contents of AX with val2 and demonstrating memory-to-
memory exchange.
String Conversion and Output: The dwtoa function is invoked multiple times to convert
the results of various register manipulations to strings, which are then displayed using StdOut.
Demonstration of Various Instructions: The program showcases different assembly
instructions such as MOV, MOVZX, MOVSX, and XCHG, demonstrating how they manipulate
registers and memory.
OBJECTIVES:
Arithmetic Operations: Performs increment, decrement, negation, addition, and subtraction
on registers and memory values.
Flag Handling: Manipulates and checks zero flag (ZF), sign flag (SF), and carry flag (CF)
after arithmetic operations using LAHF.
Flag Examples: Demonstrates how specific operations affect flags like ZF, SF, and CF, with
results stored and displayed.
String Conversion: Uses dwtoa to convert register values and flags into strings for display
with StdOut.
Memory-Register Interaction: Moves values between memory and registers to perform
arithmetic and logical operations.
Task 2: Using the XCHG instruction no more than three times, reorder the
values in four 8-bit registers from the order A, B, C, D to B, C, D, A.
OBJECTIVES:
Initial Value Assignment: Assigns values to four data points and loads them into four
separate registers.
Initial Display: Outputs the initial sequence of values before swapping.
Value Swapping: Uses the exchange (XCHG) instruction to reorder the values between the
registers.
Final Display: Outputs the new sequence of values after the exchange operations.
Program Termination: Exits the program cleanly using the ExitProcess call.
Task 3: Implement the following arithmetic expressions in assembly
language: CLO-1
1. EAX =– val 2+ 7 – val3+ val 1(Assume that val1, val2, and val3 are 32-bit
integer variables)
2. AX=(val 2+BX )– val 4 (Assume that val2 and val4 are 16-bit integer
variables.)
OBJECTIVES:
val1, val2, and val3: The program initializes three 32-bit variables with values (45, 37, and
78, respectively).
Mathematical operations: The value of val3 is negated, then added to val1. Next, val2 is
also negated and added. Finally, a constant value of 7 is added to complete the calculations.
Result storage: After performing these operations, the result is stored in the eax register.
Display output: The result is converted to a string and displayed using Stdout.
Program exit: The program terminates by calling exit.
Task 4: Develop a program that uses INC, DEC, and NEG instructions to
manipulate the contents of registers and shows the change in values.
CLO-1