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

Assembly Language Lab #1: Eng. Hala O. Abu Radi

This document provides an introduction to assembly language concepts including: 1) Data transfer instructions like MOV, MOVSX, MOZX, and XCHG 2) Arithmetic instructions like INC, DEC, ADD, SUB, and NEG 3) Several exercises are provided to demonstrate using these instructions to transfer data, perform arithmetic operations, and debug code. The exercises include initializing variables, exchanging variable values, incrementing/decrementing arrays, and performing additions/subtractions. Homework assignments are also provided.

Uploaded by

jemayuso
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)
46 views

Assembly Language Lab #1: Eng. Hala O. Abu Radi

This document provides an introduction to assembly language concepts including: 1) Data transfer instructions like MOV, MOVSX, MOZX, and XCHG 2) Arithmetic instructions like INC, DEC, ADD, SUB, and NEG 3) Several exercises are provided to demonstrate using these instructions to transfer data, perform arithmetic operations, and debug code. The exercises include initializing variables, exchanging variable values, incrementing/decrementing arrays, and performing additions/subtractions. Homework assignments are also provided.

Uploaded by

jemayuso
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/ 12

2012

2012
Assembly
Language
Lab #1

Eng. Hala O. Abu Radi


Islamic University of Gaza

Eng. Hala O. Abu Radi


Assembly Language Lab # 2
Data Transfer & Arithmetic (1)
Objective:
To be familiar with Assembly Language

Introduction:
1. Data Transfer

 MOV Instruction
Move from source to destination.

Note that : No more than one memory operand permitted , the registers CS, EIP, and
IP cannot be the destination and No immediate to segment moves

Syntax:

MOV destination,source

 MOVZX
When you copy a smaller value into a larger destination, the MOVZX instruction fills
(extends) the upper half of the destination with zeros.

Syntax:

MOVZX destination,source
 MOVSX
The MOVSX instruction fills the upper half of the destination with a copy of the
source operand's sign bit.

Syntax:

MOVSX destination,source

 XCHG Instruction
XCHG exchanges the values of two operands. At least one operand must be a register.
No immediate operands are permitted.

2. Arithmetic( Adding and Subtracting Numbers)

 INC destination

destination  destination + 1

Add 1 from destination operand ,operand may be register or memory

 DEC destination

destination  destination – 1

subtract 1 from destination operand ,operand may be register or memory

 ADD instruction
Previous labs have already used the ADD instruction. The form of the ADD
instruction is:
ADD destination, source ;dest operand = dest operand + source operand

The destination operand can be a register or in memory. The source operand can be a
register, in memory or immediate.
Flags:
ZF = 1 iff dest + src = 0
SF = 1 iff dest + src < 0
CF = 1 iff dest + src generated carry out of most significant bit
OF = 1 iff dest + src resulted in signed overflow
AF = 1 iff when an operation produces a carry out from bit 3 to bit 4
PF = 1 iff an instruction generates an even number of 1 bits in the low byte of the
destination operand.
 SUB instruction

SUB dest, source ;dest = dest – source

Flags:
ZF = 1 iff dest - src = 0
SF = 1 iff dest - src < 0
CF = 1 iff required a borrow at most-significant-bit
OF = 1 iff resulted in signed overflow
AF = 1 iff resulted in borrow into the low-ordered four bit of 8-,16-, or 32-bit
operands
PF = 1 iff an instruction generates an even number of 1 bits in the low byte of the
destination operand.

 NEG (negate) Instruction

Reverses the sign of an operand. Operand can be a register or memory operand.

Lab work:
Excercise1:
Use the following variables with attached assembly code to initialize ebx to the value
1234ABEFh
var1 = 12345678h
var2 = 0ABCDh
var3 = 0EFh

Note :Use MASM assembler


Assemble file
Debugg File

Excericse2:
Repeat the previous exercise without using the equal sign directive. Define the three
variable using data definition statements.
Exercise3:
Exchange the content of the following variables
Var1 dw 1000h
Var2 dw 2000h

1. Open new File called lab23

2. Assemble it
2
3. Linking it
.
4.Execute it .

5.Debug it .
Var1 and Var2 in Data Segment before exchanging :

Var1 Exchanging Operation


Var2
doesn't executed yet

Var1 and Var2 in Data Segment after exchanging :

Var1 Var2
Exercise4:
print the following output on the command window
*
**
***
****
*****
Debugger :

Offset msg1

Offset msg2

Offset msg3

Offset msg4

Offset msg5

Exercise5:
Write a code to increment the odd elements in the array numbers and decrement the
even elements on the same array
Numbers 1, 2, 3, 4
Debugger :

numbers array

Data Segment after code execution :


Exercise6:
Debug the following code to find which flags will be after each instructions from
these flags (CF, ZF, OF, SF)

mov ax,7FFOh
add al,1Oh
add ah,1
add ax,2

Excericse7:
Write an assembly code that perform the following addition
val1= (-Al+ Bl) - va12.
Consider the following intialization
val1 db ??
val2 db 23
mov al,17
mov bl,29
H.W1:
Write an assembly code to put the byte array Vowels in the double word array
New_Vowels in the opposite direction
Vowels db a,e,i,o,u
New_Vowels dd 5 dup(?)
Then print the content of array New_Vowels

H.W2:
use the array odd to find the square of the numbers between 1 and 5 and put the
square of each number in the array square
odd db 1,3,5,7,9
square 5 dup(?)

H.W3:
How can you calculate the result of 7FFFh+FFFFh without causing the carry flag to
be set

The END

With All My best Wishes

You might also like