Loops and Code Reviews-Assembly Language Programming-Lab Slides, Slides of Assembly Language Programming

Prof. Abhay Aggrawal delivered this lecture at Birla Institute of Technology and Science for lab of Assembly Language Programming. It includes: CMP, JCXZ, LOOP, Signs, Zeros, Caryy, Parity, Overflow, Multiplication, Doubleword, Flag, Initializers

Typology: Slides

2011/2012

Uploaded on 07/26/2012

parina
parina 🇮🇳

4.4

(67)

222 documents

1 / 32

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab 6
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download Loops and Code Reviews-Assembly Language Programming-Lab Slides and more Slides Assembly Language Programming in PDF only on Docsity!

  • Lab

Summary

 CMP

 JCXZ

 LOOP

 CodeView

Comparison Instruction

 Comparison Instruction (CMP) is an

instruction that only changes the flag

bits

 Useful for checking the entire contents

of a register or a memory location

against another value

 Followed by a conditional jmp

instruction

CMP continued

 Conditional jumps that follow the comparison

are JA, JB …

 For example:

CMP AL, 10 H

JAE SUBER

Conditional jump instructions test the following

flag bits sign(S), zero(Z), carry(C), parity(P),

overflow(O)

JLE Z=1 or S<>0 Jump is less than or equal

JNC C=0 Jump if no carry

JNE or JNZ Z=0 Jump if not equal, jump if not zero

JNO O=0 Jump if no overflow

JNS S=0 Jump if no sign

JNP or JPO P=0 Jump if no parity, jump if parity odd

JO O=1 Jump if overflow set

JP or JPE P=1 Jump if parity set, jump if parity even

JS S=1 Jump is sign is set

JECXZ ECX = 0 Jump if ECX is zero

JCXZ CX=0 Jump if CX is zero

Singed and unsigned

comparisons

 When signed numbers are compared

use the JG, JL, JGE, JLE, JE, JNE

 The terms greater than or less than refer

to singed numbers

 When unsigned numbers are compared

use JA, JB, JAE, JBE, JE, JNE

 The terms below and above refer to

unsigned numbers

LOOP instruction

 Loop is a combination of decrement CX

and JNZ conditional jump

 Loop decrements CX if CX <> 0 it

jumps to the address indicated

otherwise continues with next

sequential instruction

Multiplication instructions

 80×86 architecture has two multiplication instruction mnemonics  imul instruction treats its operands as signed numbers; the sign of the product is determined by the usual rules for multiplying signed numbers  mul instruction treats its operands as unsigned binary numbers; the product is also unsigned  If only non-negative numbers are to be multiplied, mul should usually be chosen instead of imul since it is a little faster

Mul continued…

 source has byte length, then it is multiplied by the

byte in AL; the product is 16 bits long, with a destination of the AX register

 If source has word length, then it is multiplied by the

word in AX; the product is 32 bits long, with its low order 16 bits going to the AX register and its high order 16 bits going to the DX register

 If source is a doubleword, then it is multiplied by the

doubleword in EAX; the product is 64 bits long, with its low order 32 bits in the EAX register and its high order 32 bits in the EDX register

Mul continued…

 For byte multiplication, the original value in

AX is replaced

 For word multiplication, the original values in

AX and DX are both wiped out. Similarly, for

doubleword multiplication the values in EAX

and EDX are replaced by the product.

 In each case the source operand is

unchanged unless it is half of the destination

location.

MUL continued

 AX: 00:

 BX: 00:

 DX: ??:??

 Mul bx

 DX:00:

 AX: 00:0A

 AX:00:

 Byte at factor FF

 Mul factor

 AX: 04:FB

 CF, OF 1

Imul instructions

 imul register, source

 source operand can be in a register, in

memory, or immediate

 other factor is in the register, which also

serves as the destination

 Operands must be words or doublewords, not

bytes

 product must "fit" in same size as the factors;

if it does, CF and OF are cleared to 0, if not

they are set to 1

Imul continued…

 third imul format is

 imul register, source, immediate

 the first operand, a register, is only the

destination for the product

 the two factors are the contents of the register

or memory location given by source and the

immediate value

 Operands register and source are the same

size, both 16-bit or both 32-bit

 If the product will fit in the destination register,

then CF and OF are cleared to 0; if not, they

are set to 1 docsity.com