Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Carter P.A.PC assembly language.2005.pdf
Скачиваний:
15
Добавлен:
23.08.2013
Размер:
1.07 Mб
Скачать

Chapter 1

Introduction

1.1Number Systems

Memory in a computer consists of numbers. Computer memory does not store these numbers in decimal (base 10). Because it greatly simplifies the hardware, computers store all information in a binary (base 2) format. First let’s review the decimal system.

1.1.1Decimal

Base 10 numbers are composed of 10 possible digits (0-9). Each digit of a number has a power of 10 associated with it based on its position in the number. For example:

234 = 2 × 102 + 3 × 101 + 4 × 100

1.1.2Binary

Base 2 numbers are composed of 2 possible digits (0 and 1). Each digit of a number has a power of 2 associated with it based on its position in the number. (A single binary digit is called a bit.) For example:

110012 = 1 × 24 + 1 × 23 + 0 × 22 + 0 × 21 + 1 × 20

=16 + 8 + 1

=25

This shows how binary may be converted to decimal. Table 1.1 shows how the first few numbers are represented in binary.

Figure 1.1 shows how individual binary digits (i.e., bits) are added. Here’s an example:

1

2

 

 

 

CHAPTER 1. INTRODUCTION

 

 

 

 

 

 

 

 

Decimal

Binary

 

Decimal

Binary

 

0

0000

 

8

1000

 

 

1

0001

 

9

1001

 

 

2

0010

 

10

1010

 

 

3

0011

 

11

1011

 

 

4

0100

 

12

1100

 

 

5

0101

 

13

1101

 

 

6

0110

 

14

1110

 

 

7

0111

 

15

1111

 

Table 1.1: Decimal 0 to 15 in Binary

 

 

No previous carry

 

 

 

 

Previous carry

 

 

0

0

1

 

1

 

0

0

1

 

1

 

+0

+1

+0

 

+1

 

+0

+1

+0

 

+1

 

 

0

 

1

 

1

 

0

 

 

1

 

0

 

0

 

1

 

 

 

 

 

 

 

 

c

 

 

 

c

 

c

c

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 1.1: Binary addition (c stands for carry)

110112

+100012

1011002

If one considers the following decimal division:

1234 ÷ 10 = 123 r 4

he can see that this division strips o the rightmost decimal digit of the number and shifts the other decimal digits one position to the right. Dividing by two performs a similar operation, but for the binary digits of the number. Consider the following binary division1:

11012 ÷ 102 = 1102 r 1

This fact can be used to convert a decimal number to its equivalent binary representation as Figure 1.2 shows. This method finds the rightmost digit first, this digit is called the least significant bit (lsb). The leftmost digit is called the most significant bit (msb). The basic unit of memory consists of 8 bits and is called a byte.

1The 2 subscript is used to show that the number is represented in binary, not decimal

1.1. NUMBER SYSTEMS

3

Decimal Binary

25 ÷ 2 = 12 r 1 11001

÷ 10

= 1100 r 1

12

÷

2

= 6 r 0

1100

÷ 10

= 110 r 0

6

÷

2

= 3 r 0

110

÷ 10

= 11 r 0

3 ÷ 2 = 1 r 1

11 ÷ 10 = 1 r 1

1 ÷ 2 = 0 r 1

1 ÷ 10 = 0 r 1

Thus 2510 = 110012

Figure 1.2: Decimal conversion

589

÷ 16

=

36 r 13

36

÷ 16

=

2 r 4

2

÷ 16

=

0 r 2

Thus 589 = 24D16

Figure 1.3:

1.1.3Hexadecimal

Hexadecimal numbers use base 16. Hexadecimal (or hex for short) can be used as a shorthand for binary numbers. Hex has 16 possible digits. This creates a problem since there are no symbols to use for these extra digits after 9. By convention, letters are used for these extra digits. The 16 hex digits are 0-9 then A, B, C, D, E and F. The digit A is equivalent to 10 in decimal, B is 11, etc. Each digit of a hex number has a power of 16 associated with it. Example:

2BD16 = 2 × 162 + 11 × 161 + 13 × 160

=512 + 176 + 13

=701

To convert from decimal to hex, use the same idea that was used for binary conversion except divide by 16. See Figure 1.3 for an example.

The reason that hex is useful is that there is a very simple way to convert

Соседние файлы в предмете Электротехника