1 of 14

Machine Instructions

COMPUTER ORGANIZATION

Prepared by

Mr. SUTHAGAR S/ AP/ ECE

Prepared By : Mr. SUTHAGAR S / AP / ECE

2 of 14

Machine Instructions and Programs

Prepared By : Mr. SUTHAGAR S / AP / ECE

3 of 14

Objectives

  • Machine instructions and program execution, including branching and subroutine call and return operations.
  • Number representation and addition/subtraction in the 2’s-complement system.
  • Addressing methods for accessing register and memory operands.
  • Assembly language for representing machine instructions, data, and programs.
  • Program-controlled Input/Output operations.

Prepared By : Mr. SUTHAGAR S / AP / ECE

4 of 14

Number, Arithmetic Operations, and Characters

Prepared By : Mr. SUTHAGAR S / AP / ECE

5 of 14

Signed Integer

  • 3 major representations:

Sign and magnitude

One’s complement

Two’s complement

  • Assumptions:

4-bit machine word

16 different values can be represented

Roughly half are positive, half are negative

Prepared By : Mr. SUTHAGAR S / AP / ECE

6 of 14

Sign and Magnitude Representation

High order bit is sign: 0 = positive (or zero), 1 = negative

Three low order bits is the magnitude: 0 (000) thru 7 (111)

Number range for n bits = +/-2n-1 -1

Two representations for 0

Prepared By : Mr. SUTHAGAR S / AP / ECE

7 of 14

One’s Complement Representation

  • Subtraction implemented by addition & 1's complement
  • Still two representations of 0! This causes some problems
  • Some complexities in addition

Prepared By : Mr. SUTHAGAR S / AP / ECE

8 of 14

Two’s Complement Representation

  • Only one representation for 0
  • One more negative number than positive number

like 1's comp

except shifted

one position

clockwise

Prepared By : Mr. SUTHAGAR S / AP / ECE

9 of 14

Binary, Signed-Integer Representations

0

0

0

0

0

0

0

0

1

1

1

1

1

1

1

1

0

0

0

0

0

0

0

0

1

1

1

1

1

1

1

1

1

1

0

0

1

1

0

0

0

0

1

1

0

0

1

1

1

0

1

0

1

0

1

0

0

1

0

1

0

1

0

1

1

+

1

-

2

+

3

+

4

+

5

+

6

+

7

+

2

-

3

-

4

-

5

-

6

-

7

-

8

-

0

+

0

-

1

+

2

+

3

+

4

+

5

+

6

+

7

+

0

+

7

-

6

-

5

-

4

-

3

-

2

-

1

-

0

-

1

+

2

+

3

+

4

+

5

+

6

+

7

+

0

+

7

-

6

-

5

-

4

-

3

-

2

-

1

-

b

3

b

2

b

1

b

0

Sign and

magnitude

1'

s complement

2'

s complement

B

V

alues represented

Binary, signed-integer representations.

Prepared By : Mr. SUTHAGAR S / AP / ECE

10 of 14

Addition and Subtraction – 2’s Complement

4

+ 3

7

0100

0011

0111

-4

+ (-3)

-7

1100

1101

11001

4

- 3

1

0100

1101

10001

-4

+ 3

-1

1100

0011

1111

If carry-in to the high

order bit =

carry-out then ignore

carry

if carry-in differs from

carry-out then overflow

Simpler addition scheme makes twos complement the most common

choice for integer number systems within digital systems

Prepared By : Mr. SUTHAGAR S / AP / ECE

11 of 14

2’s-Complement Add and Subtract Operations

1 1 0 1

0 1 1 1

0 1 0 0

0 0 1 0

1 1 0 0

1 1 1 0

0 1 1 0

1 1 0 1

0 0 1 1

1 0 0 1

0 1 0 1

1 1 1 0

1 0 0 1

1 1 1 1

1 0 0 0

0 0 1 0

0 0 1 1

0 1 0 1

4

+

(

)

2

-

(

)

3

+

(

)

2

-

(

)

8

-

(

)

5

+

(

)

+

+

+

+

+

+

1 1 1 0

0 1 0 0

1 0 1 0

0 1 1 1

1 1 0 1

0 1 0 0

6

-

(

)

2

-

(

)

4

+

(

)

3

-

(

)

4

+

(

)

7

+

(

)

+

+

(b)

(d)

1 0 1 1

1 1 1 0

1 0 0 1

1 1 0 1

1 0 0 1

0 0 1 0

0 1 0 0

0 1 1 0

0 0 1 1

1 0 0 1

1 0 1 1

1 0 0 1

0 0 0 1

0 0 1 0

1 1 0 1

0 1 0 1

0 0 1 0

0 0 1 1

5

-

(

)

2

+

(

)

3

+

(

)

5

+

(

)

2

+

(

)

4

+

(

)

2

-

(

)

7

-

(

)

3

-

(

)

7

-

(

)

6

+

(

)

3

+

(

)

1

+

(

)

7

-

(

)

5

-

(

)

7

-

(

)

2

+

(

)

3

-

(

)

+

+

-

-

-

-

-

-

(a)

(c)

(e)

(f)

(g)

(h)

(i)

(j)

Figure 2.4. 2's-complement Add and Subtract operations.

Page 31

Prepared By : Mr. SUTHAGAR S / AP / ECE

12 of 14

Overflow - Add two positive numbers to get a negative number or two negative numbers to get a positive number

5 + 3 = -8

-7 - 2 = +7

0000

0001

0010

0011

1000

0101

0110

0100

1001

1010

1011

1100

1101

0111

1110

1111

+0

+1

+2

+3

+4

+5

+6

+7

-8

-7

-6

-5

-4

-3

-2

-1

0000

0001

0010

0011

1000

0101

0110

0100

1001

1010

1011

1100

1101

0111

1110

1111

+0

+1

+2

+3

+4

+5

+6

+7

-8

-7

-6

-5

-4

-3

-2

-1

Prepared By : Mr. SUTHAGAR S / AP / ECE

13 of 14

Overflow Conditions

5

3

-8

0 1 1 1

0 1 0 1

0 0 1 1

1 0 0 0

-7

-2

7

1 0 0 0

1 0 0 1

1 1 0 0

1 0 1 1 1

5

2

7

0 0 0 0

0 1 0 1

0 0 1 0

0 1 1 1

-3

-5

-8

1 1 1 1

1 1 0 1

1 0 1 1

1 1 0 0 0

Overflow

Overflow

No overflow

No overflow

Overflow when carry-in to the high-order bit does not equal carry out

Prepared By : Mr. SUTHAGAR S / AP / ECE

14 of 14

Sign Extension

  • Task:
    • Given w-bit signed integer x
    • Convert it to w+k-bit integer with same value
  • Rule:
    • Make k copies of sign bit:
    • X = xw–1 ,…, xw–1 , xw–1 , xw–2 ,…, x0

k copies of MSB

• • •

X

X

• • •

• • •

• • •

w

w

k

Prepared By : Mr. SUTHAGAR S / AP / ECE