/
CET 3510 - Microcomputer Systems Technology CET 3510 - Microcomputer Systems Technology

CET 3510 - Microcomputer Systems Technology - PowerPoint Presentation

giovanna-bartolotta
giovanna-bartolotta . @giovanna-bartolotta
Follow
351 views
Uploaded On 2018-11-25

CET 3510 - Microcomputer Systems Technology - PPT Presentation

Lecture 6 Dr José M Reyes Álamo 1 Review Statement Labels Unconditional Jumps Conditional Jumps Outline A low level control structure usually transfers control from one point in your program to another ID: 733723

bits bit instruction set bit bits set instruction manipulation string operand jump flag jmp clear xor label register eax

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "CET 3510 - Microcomputer Systems Technol..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

CET 3510 - Microcomputer Systems TechnologyLecture 6

Dr. José M. Reyes Álamo

1Slide2

Review:Statement LabelsUnconditional Jumps

Conditional Jumps

OutlineSlide3

A low level control structure usually transfers control from one point in your program to another.Transfer destination is typically specified of using a statement label.

A statement label consists of a valid HLA identifier and a colon.Don’t have to be declared before you use it Syntax

aLabel

:

Statement LabelsSlide4

Transfer control to a label via a jump (goto

) instructionCall a label via the CALL instruction,

Take the address of a label

Use the address-of operator

&

Use the command load effective address

lea

Syntax: lea( reg32, Memory_operand );

Operations with LabelsSlide5

The jmp (jump) instruction unconditionally transfers control to another point in the program.

There are three forms of this instruction one direct jump, and two indirect in the following forms:jmp

label;

jmp

( reg32 );

jmp

( mem32 );

Unconditional Jump (JMP)Slide6

Direct jump specifies the target using a label The label is usually on the same line as an executable instruction or appears on a line preceding an executable machine instruction.

The direct jump instruction is the most commonly used. Equivalent to a GOTO statement

Syntax:

jmp

laterInPgm

;…laterInPgm:…Direct JumpSlide7

Transfers control to the instruction whose address is specified in the 32-bit general purpose register.You must load the specified register with the address of some machine instruction prior to the execution of the JMP.

Syntax:…

mov

(&

laterInPgm

,

ebx

);jmp (ebx);…laterInPgm:…

Register Indirect JumpSlide8

Memory indirect fetches a dword value from the specified memory location and transfers control to the instruction at the address specified by the contents of the memory location.

Similar to the register indirect JMP except the address appears in a memory location rather than in a register.Syntax:

<< statements >>

LabelPtr:dword

:= &

stmtLabel

;

…jmp (LabelPtr);…

stmtLabel

:

Memory Indirect JumpSlide9

Unconditional jmp provides transfer of control but does not allow you to make decisions.

Conditional jumps handle this task.Conditional jumps are the basic tool for creating loops (i.e.

while, for, repeat

) and other conditionally executable statements (i.e.

if, switch

)

Syntax

jcc label;cc indicated the type of test you are performing.Conditional JumpSlide10

The conditional jumps test one or more flags in the EFLAGS register to see if they match a particular pattern.

If the flags match, the control jumps to the target label.If the match fails, the CPU ignores the conditional jump and execution continues with the next instruction.Most of the time, conditional jumps follow the execution of a

cmp

instruction as the

cmp

sets the EFLAGS register allowing tests for less than, greater than, equality, etc.

Conditional Jump TestsSlide11

Bit ManipulationSlide12

A bit string is a contiguous sequence of one or more bits

A bit string does not have to start or end at any special point. A bit string could start in bit seven of one byte in memory and continue through to bit six of the next byte.

A bit string could begin in bit 30 of EAX, and continue from bit zero through 17 of ECX.

In memory, bits must be physically contiguous

In registers, the application defines the continuation register.

Bit StringSlide13

A bit set is a collection of bits, not necessarily contiguous within some larger data structure.

e.g. 0..3, 7, 12, 24, and 31 from some double word object forms a set of bits.Usually, we will limit bit sets to some reasonably sized

container object

.

Normally, container object sizes are about 32 or 64 bits

Bit strings are special cases of bit sets.

Bit SetSlide14

A bit run is a sequence of bits with all the same value.

A run of zeros is a bit string containing all zeros.A

run of ones

is a bit string containing all ones.

The

first set bit

is

the position in a bit string of the first bit containing a onei.e., the first bit set to ‘1’.The first clear bit is the

position in a bit string of

the first bit containing a

zero

i.e., the first bit set to

‘0’.

The

last set bit

is the last bit position in a bit string containing a ‘1’; followed by a run of zeros.

The

last clear bit

is the last bit position in a bit string containing a ‘0’; followed by a run of ones.

Bit RunSlide15

A bit offset is the number of bits from some boundary position (usually a byte boundary) to the specified bit.

Bits are numbered starting from zero at the boundary location.If the offset is less than 32, then the bit offset is the same as the bit number in a byte, word, or double word value.

Bit OffsetSlide16

A mask is a sequence of bits used to manipulate certain bits in another value.e.g. mask 0000_1111_0000 used with AND, clears all the bits except bits

4-7mask 0000_1111_0000 used with OR, sets the bits 4-7 and preserves

the bits 0-3 and 8-11

Bit MaskSlide17

Bit manipulation generally consists of six activities:

Setting bitsClearing bits

Inverting bits

Testing and comparing bits

Extracting bits

Inserting bits

Bit manipulation instructions:

ANDOR

XOR

NOT

Shift

Rotate

Bit ManipulationSlide18

The AND instruction provides the ability to strip away unwanted bits from a bit sequence and replace them with zeros. e.g. suppose that a bit string consumes bits 12-24 of EAX. We can isolate it by setting all other bits to zero and using the

and instruction: and( %1_1111_1111_1111_0000_0000_0000,

eax

);

Most programs use AND to clear bits that are not part of the desired bit string.

Bit Manipulation: ANDSlide19

Bit Manipulation: ANDSlide20

To check if the bits 12-24 of EAX contain $12F3 you could use the following code:

Or a more sophisticated one:Most of the time the bit string is aligned to position zero:

Bit Manipulation: ANDSlide21

OR instruction allows you to mask unwanted bits. OR instruction does not let you clear bits but it allows you to set bits.

The OR instruction is especially useful for inserting a bit set into some other bit string:Clear all the bits surrounding your bit set in the source operand.

Clear all the bits in the destination operand where you wish to insert the bit set.

OR the bit set with the destination operand.

Bit Manipulation: ORSlide22

Assume that you have a value in bits 0-12 of EAX that you want to insert into bits 12-24 of EBX without affecting any of the other bits in EBX.

First you strip bits 13-31 EAX; then strip out bits 12-24 in EBX. Next, shift the bits in EAX to positions 12-24. Finally, OR the values of EAX and EBX

Bit Manipulation: ORSlide23

Bit Manipulation: ORSlide24

Bit Manipulation: ORSlide25

Bit Manipulation: ORSlide26

When working with bit masks, it is poor software engineering to use literal numeric constants.

You should always create symbolic constants instead to produce code that

is

easier

to read and maintain.

Bit Manipulation: ORSlide27

VS.

Bit Manipulation: ORSlide28

NOT: Used to invert all the bits. Not very interesting.XOR: gives you the ability to invert selected bits belonging to a bit set.

XOR lets you manipulate known data in just about any way imaginable.Can accomplish the same results as with AND or OR

, but with two advantages:

You are not limited to forcing the field to all zeros or all ones, you can have combinations;

You can manipulate other bits in the destination operand at the same time.

NOT and XORSlide29

Suppose that you know that one field contains 1010 that you want to force to zero and another field contains 1000 that you wish to increment by one. You cannot accomplish both operations with a single AND or

OR instruction, but you can do this with a single XOR instructionHow? XOR the first field with %1010 and the second field with %0001.

Warning

: This trick only works if you know the current value of a bit set within the destination operand.

XOR

ExampleSlide30

AND, OR, and XOR affect the EFLAGs register as follows: These instructions always clear the carry and overflow flags.

These instructions set the sign flag if the result has a one in the H.O. bit; they clear it otherwise.These instructions set/clear the zero flag depending on whether the result is zero.

These instructions set the parity flag if there are an even number of set bits in the L.O. byte of the destination operand, clear the parity flag if there are an odd number of one bits in the L.O. byte of the destination operand.

How EFLAGS is affectedSlide31

Parity is a very simple error detection scheme.The idea was to count the number of set bits in a character and include an extra bit in the transmission to indicate whether that character contained an even or odd number of set bits.

The receiving end of the transmission would also count the bits and verify that the extra “parity” bit indicated a successful transmission.

The purpose of the parity flag is to help compute the value of this extra bit.

The 80x86 AND, OR, and XOR instructions set the parity bit if the L.O. byte of their operand contains an

even

number of set bits.

Not used that much any more.

About the Parity FlagSlide32

After executing AND/OR/XOR, the zero flag result is one of the most important.Many programs often reference this flag after the AND instruction.

Intel added the instruction TEST that logically AND two results and set the flags without affecting either instruction operand.

Bit Manipulation: TESTSlide33

There are three main uses of the zero flag after executing AND or TEST Checking to see if a particular bit in an operand is set.

Checking to see if at least one of several bits in a bit set is one.

Checking to see if an operand is zero.

Bit Manipulation: TESTSlide34

Many of these instructions to manipulate bit will set the carry flag:

RCL, RCRJC, JNCSETC, SETNC

These are rarely used but are available if needed.

Carry Flag as a Bit Accumulator