Presentation on theme: "Machine Instructions Operations"— Presentation transcript:
1 Machine Instructions Operations ITCS 3181 Logic and Computer Systems B. Wilkinson Slides4-1A.ppt Modification date: March 18, 2015
2 InstructionsWe will use a simple instruction formats of a so-called reduced instruction set computer (RISC), which has the characteristics:Simple, fixed length instruction formatA few addressing modesLimited number of operationsDesigned to achieve high speed of executionIt was recognized in the 1980’s that such processors would actually execute programs faster that the prevalent CISCs (complex instruction set computers).
3 Instruction formatOur instruction format is quite similar to the G4/G5 PowerPC and SUN Sparc processors and also similar but not identical to that used in the assembly language simulator in the labs.Intel 64/IA32 processor family -- uses a very complex and archaic instruction format, based upon the early 8086 processor (which was themselves loosely based upon even earlier Intel processors).However Intel processors now convert this complex instruction format (CISC) internally to simpler RISC formats for performance reasons.
4 Some Key Features of Processor Used Thirty-two 32-bit integer registers called R0 to R312. One register, R0, holds zero permanently3 All arithmetic done only between registers:- Three-register formatop-code, destination register, source register 1, source register 2or- Immediate addressingop-code destination register, source register, constant4. Memory operations limited to:load register, andstore registerusing register indirect addressing plus offset only:LD/LB destination register, offset[source register]ST/SB source register, offset[source register]R0R1R2R31R30R3R29R4R280000 … 0000R31 holds return address for procedures.R29 is a stack pointer see later.
5 Data Transfer Examples Instruction Comments Instructions that copy the contents of one location to another location.ExamplesMOV R1,R2 ;R1 = R2LD R3,100[R2] ;Contents of memory whose address is;given by R2 copied to R3.ST [R5],R4 ;Contents of R4 copied to memory loc.;whose address held in R5. (Offset = 0)Note LD and ST cause 32-bit transfers.Use LB and SB to cause 8-bit transfers.InstructionComments
6 Arithmetic Instructions Performs an arithmetic operation such as addition, subtraction, multiplication or division.ExamplesADD R1,R2,R3 ;R1 = R2 + R3SUB R5,R4,3 ;R5 = R4 – 3For literals (immediate addressing) differences in assembly language notation. Might be written as:SUB R5,R4,#3 ;R5 = R4 - 3orSBI R5,R4,3 ;R5 = R4 - 3depending upon assembly language.
7 C/Java Language Examples Logical InstructionsPerforms bit-wise logical operation such as AND, OR, exclusive-OR, or NOT. AND, OR, exclusive-OR operate upon pairs of bits of two operands.Bit-wise AND, OR, Ex-OR, and NOT are available in C and Java (although you probably did not come across them!):C/Java Language Examplesy = y & 1 ;bit-wise AND y with the number 1z = z | 2 ;bit-wise OR z with the number 2
9 C/Java language Examples Shift InstructionsMoves the bits of a location one or more places left or right.Again available in C/Java (although you probably did not come across them!):C/Java language Examplesy = y << 1 ;shift y 1 place left 1z = z >> 2 ;shift z 2 places right
10 Machine Instruction Examples SHL R1,R1,1 ;Shift R1 left one placeSHR R1,R1,1 ;Shift R1 right one placeX = 0 or 1 see next slide
11 Arithmetical and Logical Shifts Two types of shift usually provided:“Logical” shift (SHL, SHR)Fill free end with 0, i.e. X = 0.“Arithmetic” shift (SAL, SAR)Arithmetic shifts multiple/divide by 2.Arithmetic shift right maintains value of sign bit, i.e. X = value of original sign bit.
12 Example Starting with a number 9 000 ... 0001001 Shift arithmetic left one place. GetShift arithmetic right two places. Geti.e. lost the 0.5.
13 Note: Java has logical shift right - called unsigned right shift, >>>. Examplex = x >>> 2;
14 QuestionWhat is the difference, if any, between arithmetic shift left and logical shift left, i.e. what is the difference, if any, between:SHL R1, R1, 1andSAL R1, R1, 1AnswerArithmetic shift left same as logical shift left (except arithmetic overflow may be detected).
15 Question Answer What is the effect of the sequence? SAR R1, R1, 1 SAL R1, R1, 1AnswerMakes number even if odd, i.e. 5 would become 4
16 Rotate Instructions Examples Moves bits of location one or more places left of right in a circular fashion.ExamplesROL R1,R1,1 ;Rotate R1 left one placeROR R1,R1,1 ;Rotate R1 right one placeVersion of rotate exists where the rotate passes thro a Carry flag within the condition code register, see later about the CCR