IntegerArithmetic - Integer Arithmetic Integer Arithmetic...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Integer Arithmetic Beta Draft - Do not distribute © 2001, By Randall Hyde Page 587 Integ er Arithmetic Chapter Ten 10.1 Chapter Overview This chapter discusses the implementation of arithmetic computation in assembly language. By the conclusion of this chapter you should be able to translate (inte ger) arithmetic e xpressions and assignment statements from high le v el languages lik e P ascal and C/C++ into 80x86 assembly language. 10.2 80x86 Integer Arithmetic Instructions Before describing ho w to encode arithmetic e xpressions in assembly language, it w ould be a good idea to fi rst discuss the remaining arithmetic instructions in the 80x86 instruction set. Pre vious chapters ha v e co v ered most of the arithmetic and logical instructions, so this section will co v er the fe w remaining instruc - tions you’ ll need. 10.2.1 The MUL and IMUL Instructions The multiplication instructions pro vide you with another taste of irre gularity in the 80x86’ s instruction set. Instructions lik e ADD , SUB , and man y others in the 80x86 instruction set support tw o operands. Unfor - tunately , there weren’ t enough bits in the 80x86’ s opcode byte to support all instructions, so the 80x86 treats the MUL (unsigned multiply) and IMUL (signed inte ger multiply) instructions as single operand instruc - tions, lik e the INC , DEC , and NEG instructions. Of course, multiplication is a tw o operand function. T o w ork around this f act, the 80x86 al w ays assumes the accumulator ( AL ,AX, or EAX ) is the destination operand. This irre gularity mak es using multipli - cation on the 80x86 a little more dif fi cult than other instructions because one operand has to be in the accu - mulator . Intel adopted this unorthogonal approach because the y felt that programmers w ould use multiplication f ar less often than instructions lik e ADD and SUB . Another problem with the MUL and IMUL instructions is that you cannot multiply the accumulator by a constant using these instructions. Intel quickly disco v ered the need to support multiplication by a constant and added the INTMUL instruction to o v ercome this problem. Ne v ertheless, you must be a w are that the basic MUL and IMUL instructions do not support the full range of operands that INTMUL does. There are tw o forms of the multiply instruction: unsigned multiplication ( MUL ) and signed multiplica - tion ( IMUL ). Unlik e addition and subtraction, you need separate instructions for these tw o operations. The multiply instructions tak e the follo wing forms: Unsigned Multiplication: mul( reg 8 ); // returns “ax” 16 // returns “dx:ax” 32 // returns “edx:eax” mul( mem 8 16 32 Signed (Integer) Multiplication: imul( reg 8 16 32
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Chapter Ten Volume Three Page 588 © 2001, By Randall Hyde Beta Draft - Do not distribute imul( mem 8 ); // returns “ax” 16 // returns “dx:ax” 32 // returns “edx:eax” The “returns” v alues abo v e are the strings these instructions return for use with instruction composition in HLA (see “Instruction Composition in HLA” on page 558 ).
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/08/2011 for the course CS 101 taught by Professor Jitenderkumarchhabra during the Summer '11 term at National Institute of Technology, Calicut.

Page1 / 24

IntegerArithmetic - Integer Arithmetic Integer Arithmetic...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online