Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Chapter 6

Stack Instructions
Data Manipulation Instructions
Floating Point Instructions

1
Stack instructions
❖Stack is an area of memory for keeping
temporary data.
❖A stack is an array-like data structure in the
memory in which data can be stored and
removed from a location called the 'top' of
the stack.
❖The data that needs to be stored is 'pushed'
into the stack and data to be retrieved is
'popped' out from the stack.
2
Stack instructions…
Stack is a LIFO data structure, i.e., the data
stored first is retrieved last.

3
Stack instructions…
❖Assembly language provides two instructions
for stack operations:
❖PUSH and POP. These instructions have
syntaxes like −
PUSH operand
POP address/register
PUSH and POP work with 16 bit values only!

4
Stack instructions…
❖The memory space reserved in the stack
segment is used for implementing stack.
❖The registers SS and ESP (or SP) are used for
implementing the stack.
❖The top of the stack, which points to the last
data item inserted into the stack is pointed
to by the ESP register

5
6
Data manipulation instructions
❖Data manipulation instructions perform
operations on data and provide
computational capabilities for the
computer.
❖This instructions perform arithmetic , logic
and shift operations.

7
8
Examples on data manipulations
ORG 100h
.model small
.data
.code
main proc
mov ax,5h
Add ax,2
Sub ax,1
inc ax
endp
9
Example on mul and div
org 100h
.model small
.data
.code
main proc
mov ax,6h
mov bl,2h
mul/div bl
endp

10
11
Example on logical and bit
manipulation instructions
org 100h
.code
mov ax, 00000110b
Mov bx ,00000111b
And ax,bx
Or ax,bx
xor ax,bx
endp
12
13
Example on shift instructions

ORG 100h
.model small
.data
.code
main proc
mov ax, 6
shl ax,1 ; the output is 12
Shr ax, 1 ; the output is 3
endp
end main 14
Floating-point instruction
❖Floating-point instruction names begin with the
letter F to distinguish them from CPU instructions.
❖The second letter of the instruction mnemonic
(often B or I) indicates how a memory operand is
to be interpreted: B indicates a BCD operand, and
I indicates a binary integer operand.
• For example, FBLD operates on BCD numbers,
FILD operates on integers, and FLD operates on
real numbers.
15
Floating-point instruction…
• Integer operands must be loaded into the FPU from
memory (never from CPU registers); they are
automatically converted to floating-point format.
• Floating-point unit (FPU, math coprocessor) is a
part of a computer system specially designed to
carry out operations on floating-point numbers
• Similarly, when storing floating-point values into
integer memory operands, the values are
automatically truncated or rounded into integers.
16
Floating-point instruction…
• Initialization (FINIT)
The FINIT instruction initializes the FPU
• Store Floating-Point Value (FST, FSTP)
The FST (store floating-point value) instruction
copies a floating-point operand from the top of the
FPU stack into memory.
• FSTP :The FSTP (store floating-point value and
pop) instruction copies the value in ST(0) to
memory and pops ST(0) off the stack.
17
Floating-point instruction…
• Load Floating-Point Value (FLD)
The FLD (load floating-point value) instruction
copies a floating-point operand to the top of the
FPU stack [known as ST(0)].

18
Floating point data types
❖The floating-point data types supported by
MASM (QWORD, TBYTE,REAL4, REAL8, and
REAL10).

19
Floating point data types…
For example, when loading a floating-point
variable into the FPU stack, the variable is
defined as REAL4, REAL8, or REAL10:

20
Basic Floating-Point Arithmetic Instructions

21
Thank you

22

You might also like