You are on page 1of 11

DATA STORAGE AND MOVEMENT

1.0 Outcomes
At the end of this chapter, you should be able to:

1. Describe how numeric data are represented in computers


2. Describe how alphanumeric data (Characters) are represented in computers
3. Demonstrate the usage of the Mov Instruction

3.1 Data Representation within a Computer


Data can be classified into numeric and alphanumeric. The decimal digits from 0 to 9 are called

numeric data because arithmetic operations can be performed on them. Alphanumeric data, on

the other hand, comprises alphabets, numbers, and symbols.

3.1.1 Alphanumeric Data


The most common way to represent alphanumeric data is the ASCII code. The ASCII is an

acronym of American Standard Code for Information Interchange. This code assigns the letters

of the alphabet, decimal digits from 0 to 9 and some additional symbols a binary number of 7

bits, putting the 8th bit in its off state or 0. This way each letter, digit or special character

occupies one byte in the computer memory.

In most microcomputer, placing a 1 in the most significant bit uses an extended ASCII character

set. The extended ASCII is used to represent foreign letters, Greek and mathematical symbols

as well as box drawing and other special characters. Table 3.1 shows the ASCII code. Notice

that the codes from 0H to 1FH (Grey background) are called control codes and are used to

control the operation of the computer. The control codes are non-printable. Only 4 of the

control codes are shown here.


Table 3. 1 The ASCII Code

MSB 0 1 2 3 4 5 6 7

LSB 0 SP 0 @ P ' P

1 ! 1 A Q a q

2 " 2 B R b r

3 # 3 C S c s

4 $ 4 D T d t

5 % 5 E U e u

6 & 6 F V f v

7 BEL ' 7 G W g w

8 ( 8 H X h x

9 ) 9 I Y i y

A LF * : J Z j z

B ESC + ; K [ k 

C , < L \ l |

D CR _ = M ] m 

E . > N ^ n ~

F / ? O - o DEL

3.1.2 Numeric Data


Numeric data can be classified as either integer or real. Integer numbers, sometimes called

fixed point, are whole number with no decimal point, while real numbers, sometimes called

floating point, have decimal point. The 80386 family of microprocessors can only perform

arithmetic operations on integers and therefore, only the representation of integers in computer
will be discussed here. Integers can be represented in the computer as pure binary format or as

a binary coded decimal (BCD).

3.1.2.1 BCD Method


BCD is an acronym for Binary Coded Decimal. In BCD a group of 4 bits are used to represent

each decimal digit from 0 to 9. Data in BCD can be stored either as packed BCD or as unpacked

BCD. In packed BCD, each nibble of a byte represents one decimal digit. Thus, we can store

two digits per byte of information. While, in unpacked BCD, the upper nibble is set to 0 and the

lower nibble is used to store the decimal digit. Thus, we can only store one digit per byte of

information. Table 3.2 below shows how integers are stored as packed and unpacked BCD.

Table 3. 2 BCD Storage in Packed and Unpacked Format

DECIMAL PACKED UNPACKED

25 0010 0101 0000 0010 0000 0101

427 0000 0100 0010 0111 0000 0100 0000 0010 0000 0111

3.1.2.2 Integer Representation n Binary Format


Integers, signed and unsigned can be represented as a single byte, single word (2 bytes) or as

a double word (4 bytes).


3.1.2.2.1 Byte-Sized Data

An integer can be stored as a single byte (8-bits). The range for unsigned integer is from 0 to

28-1 i.e. from 0 to 255. While the range for the signed integer is from -27 to 27-1 i.e. from -128

to 127. Signed integers are stored in 2's complement, thus, the most significant bit is 1 for

negative numbers and 0 for positive numbers. Figure 3.1 shows how signed and unsigned

integers are stored as a single byte.

Binary Weights Binary Weights

128 64 32 16 8 4 2 1 -128 64 32 16 8 4 2 1

0 0 0 0 0 0 0 0 Smallest 1 0 0 0 0 0 0 0

1 1 1 1 1 1 1 1 Largest 0 1 1 1 1 1 1 1

Unsigned byte Signed byte


Figure 3.1 Single Byte Storage of Signed and Unsigned Integers

3.1.2.2.2 Word-Sized Data

An integer can be stored as a single word (16-bits). The range for unsigned integer is from 0 to

216-1 i.e. from 0 to 65535. While the range for the signed integer is from -215 to 215-1 i.e.

from -32786 to 32785. Figure 3.2a shows the largest and smallest unsigned integer stored in

word format while Figure 3.2b shows the storage of the smallest and largest signed integers are

stored as a single word format.


Binary Weights
32768 256 128 64 32 16 8 4 2 1

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Figure 3.2 a) Smallest and Largest Unsigned Integer in a 16-bit (word) format

Binary Weights
-32768 256 128 64 32 16 8 4 2 1

1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Figure 3.2 b) Smallest and Largest of a Signed Integer in a 16-bit (word) format

3.1.2.2.3 Double-Word Sized Data

An integer can be stored as a double word (32-bits). ). The range for unsigned integer is from 0

to 232-1 i.e. from 0 to 4294967295. While the range for the signed integer is from -231 to 231-1

i.e. from -2147483648 to 2147483647.

3.2 Data Storage in Memory


The Intel family of microprocessors uses the little Endian technique when storing data in

memory. This technique stores the least significant byte of data in the low memory address and

the most significant byte in the high memory address. Figure 3.3 shows how the data FA3BH is

stored in memory starting at address 0000EH.


Address Content Content

Binary Hexadecimal

00010H

0000FH 1111 1010 FA

0000EH 0011 1011 3B

0000DH

Figure 3.3 Data Storage in Memory

3.3 Declaring Variables


In assembly language, like high level language, a variable need to be declared before it can be

used. However, declaring a variable only assigns a space for it in memory and there is no type

checking by the assembler like in high level compilers. The space allocated depends whether

the variable is of Byte type, Word type or Double word type etc. All variables should be declared

in the Data segment.

1.3.1 Byte-sized Variables


The DB directive can be used to declare a variable of byte type. The syntax for this directive is:

<variable Name> db <value1>{,value2, …, valueN}

The <value1> to <valueN> can be:

• A constant between -128 to 255

• A character enclosed in single or double quote

Table 3.3 gives few examples of this directive

Table 3. 3 Examples of DB Directive

Example Description

Age db 45 Reserves a single byte in memory and assign the value 45 (2D in
Hexadecimal)

Age db ? Reserves a single byte in memory and assign no initial value

Age db 30, 50 Reserves 2 bytes in memory and assign the values 30 and 50 respectively

Age db 4 dup(0) Reserves 4 bytes in memory and assign the values 0 to all of them

Name db “Ja” Reserves 2 bytes in memory and assign the ASCII codes for J and a
respectively

1.3.2 Word-sized Variables


The DW directive can be used to declare a variable of word (2 bytes) type. The syntax for this

directive is:

<variable Name> dw <value1>{,value2, …, valueN}

The <value1> to <valueN> can be:

• A constant between -32768 to 65535

• A one or two bytes string enclosed in single or double quote

• A relative expression that requires 16 bits or less such as an offset in a segment

Table 3.4 gives few examples of this directive.

Table 3. 4 Examples of DW Directive

Example Description

Age dw 45 Reserves a single word in memory and assign the value 45

Age dw ? Reserves a single word in memory and assign no initial value

Age dw 30, -50 Reserves 2 words (4 bytes) in memory and assign the values 30 and -50
(FFCE in Hexadecimal) respectively
Age dw 4 dup(0) Reserves 4 bytes in memory and assign the values 0 to all of them

Name dw “Ja” Reserves 2 bytes in memory and assign the ASCII codes for J and a
respectively
1.3.3 Variables of Other Sizes
Similar to DB and DW which reserve 1 byte or 1 word in memory for the storage of the variable

content, there directives that can reserve double words, quadruple words and ten bytes as

shown in Table 3.5

Table 3. 5 Example of Variable of Other Sizes

Directive Example Description

DD Age dd 45 Reserves 2 words in memory and assign the value 45 to them

DQ Age DQ ? Reserves 4 words in memory and assign no initial values

DT Age DT ? Reserves 10 bytes in memory and assign no initial values

3.4 Data Movement


The move (MOV) instruction is used to move, actually copy, data between registers and/ or

memory. The general syntax is:

Mov <destination>, <source>

The destination can be a register or a memory address where the data will be stored. However,

the source can be a register, a memory address, or an immediate value. The following rules

must be observed:

• The source and destination must be of the same size

• The source and destination cannot be both segment register

• The code segment register (CS) cannot be used as a destination

• The source and destination cannot be both memory address

Table 3.6 shows examples of valid MOV instructions while Table 3.7 shows examples of invalid

MOV instructions.
Table 3. 6 Examples of Valid MOV Instructions

Instruction Description
Mov BL, 23 Store the number 23 decimal in the BL register
Mov AL, 10010010B The binary number 10010010 is stored in the AL register
mov cl, 0F3H The hexadecimal number F3 is stored in CL register
Mov DX, 7234O The Octal number 7234 is stored in the DX register
mov BX, 'AB' The ASCII code for the letters A and B are stored in the BX Register
Mov AX, BX The content of the BX register is copied into the AX register

Table 3. 7 Examples of Invalid MOV Instructions

Instruction Description
Mov CS, AX The code segment register cannot be the destination
Mov AX, BL The registers are not of the same size
Mov list1, list2 Both destination and source cannot be memory address
Mov SS, DS The source and destination cannot be both segment register

3.5 Review Questions

1) What is the ASCII code for the 'Intel 80386'?


a) 496E74656C203830333836H
b) 696E74656C203830333836H
c) 696E74656C3830333836H
2) What is the alphanumeric data represented by the ASCII code
696E74656C203830343836H
3) What is the Decimal equivalence of the packed BCD byte 10010111?
a) 79
b) 97
c) 151
4) What is the Decimal equivalence of the signed integer 10001000?
a) 136
b) -120
5) The largest unsigned integer that can be stored a single byte is?
a) 256
b) 255
c) 127
6) Show how the data 'Intel 80386' is stored in memory starting at address 00FC0H
7) Show how the signed integer -512 is stored as a word in memory starting at address
00FFFH
8) Show how the unsigned integer 234 is stored in memory starting at address 0F000H
a) As unpacked BCD
b) As packed BCD
c) As binary
9) Convert the unsigned integer 45 to packed BCD
10) For each of the mov instructions, state whether the instruction is valid or not. For the
invalid instructions, state the reason.
a) Mov AX, BL
b) Mov DS,SS
c) Mov CS, AX
d) Mov lits1, list2
e) Mov ax,5

You might also like