Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

LAB 02: Numbering system conversions & Detailed Introduction to Debug

Objectives:
1. Introduction to different numbering systems
2. Conversion between numbering systems
3. Assembly Language Syntax in debug
4. A Few basic Instructions with sample program
5. How to run the program?
6. How to break and quit the code?
7. Practices

Pre-Lab Task

Number system:

We will talk about numbering system such as binary system, hexadecimal system and decimal
system. Binary numbers mainly deal with two digits, which are zero and one. Example of binary
number is (10110011)2, 2 means base 2, and it is equivalent to (179)10, 10 means base 10.
Decimal System

Most people today use decimal representation to count. In the decimal system there are 10 digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
These digits can represent any value, for example: 754.
The value is formed by the sum of each digit, multiplied by the base (in this case it is 10 because
there are 10 digits in decimal system) in power of digit position (counting from zero):
Position of each digit is very important! For example, if you place "7" to the end: then 547 will
be another value:

Binary System

Computers are not as smart as humans are (or not yet), it's easy to make an electronic machine
with two states: on and off, or 1 and 0.
Computers use binary system, binary system uses 2 digits: 0, 1 And thus the base is 2.

There is a convention to add "b" in the end of a binary number, this way we can determine that
101b is a binary number with decimal value of 5. The binary number 10100101b equals to
decimal value of 165:
Hexadecimal System

Hexadecimal System uses 16 digits:


0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
And thus, the base is 16.
Hexadecimal numbers are compact and easy to read.
It is very easy to convert numbers from binary system to hexadecimal system and vice-versa;
every nibble (4 bits) can be converted to a hexadecimal digit.

There is a convention to add "h" in the end of a hexadecimal number, this way we can determine
that 5Fh is a hexadecimal number with decimal value of 95.
We also add "0" (zero) in the beginning of hexadecimal numbers that begin with a letter (A - F),
for example 0E120h.
The hexadecimal number 1234h is equal to decimal value of 4660:

Converting from Decimal System to Any Other

In order to convert from decimal system, to any other system, it is required to divide the decimal
value by the base of the desired system, each time you should remember the result and keep the
remainder, the divide process continues until the result is zero.
The remainders are then used to represent a value in that system.
Let's convert the value of 39 (base 10) to Hexadecimal System (base 16):

In-Lab Task:

Debug Commands

Command Description
? Displays a list of the Debug commands.

A Assembles 8086/8087/8088 mnemonics.

D Displays the contents of a portion of memory.

G Runs the executable file that is in memory.

H Performs hexadecimal arithmetic.

Q Stops the Debug session.

R Displays or alters the contents of one or more registers.

T Executes one instruction and then displays the contents of all registers

Debug: Q (Quit)

The program starts to run and ends with the first break. (Use int 3 (break) or int 20 (return to
DOS) instructions otherwise the computer is locked. If you want to save the program int 3 will
not be enough not to lock the computer. Use int 20 there. To return to DOS from debug
environment, write 'q' and quit.

Debug: H (Hex) Syntax: - H value1 value


Performs hexadecimal arithmetic on two parameters you specify.
Program Exercise 1:
Using only MOV, ADD, SUB, INC and DEC:

AX = BX – AX
AX = AX + 1
CX = AX + BX
BX = BX-1d + 10d
AX = 5h - AX
AX = 01001100b + 00011011b
BX = 10d + 23d + 32h
Program Exercise 2:

Take two values at two different memory locations, perform following operation on numbers
AND, OR, Increment (INC) first number by 4, second number by 2, Decrement (DEC) first
number by 3, second number by 1.
Show all the individual results at 6 consecutive memory locations.
Instruction
Description Example
s
Transfer data between registers, between Mov AX, Word1
register and a memory location, move a
MOV number directly into register or memory Mov AX, BX
location. Mov AH, ’A’
Exchanges the contents of two registers, or a XCHG AH, BL
XCHG register and a memory location. XCHG AX, Word1
Adds contents of two registers, a register and ADD Word1, AX
ADD a memory location, a number to a register or
memory location. ADD BL, 5
Subtracts contents of two registers, a register
SUB and a memory location, a number to a SUB AX, DX
register or memory location.
Adds 1 to the contents of a register or
INC memory location INC Word1
Subtracts 1 from a register or a memory
DEC location. Dec Byte1
AND Register1,
AND Logical AND operation
Register2
OR Logical OR operation OR Register1,
Register2

Post-Lab Assignment:

Question 1: Write code to achieve the following:

Initialize two registers AX, BX with 20h and 30h. Swap the contents of AX with BX registers.
Display the contents of the registers.
Question 2: Write codes to evaluate the arithmetic expression “15h+(6d-0000000000111010b)”,
by:
Using one register only
Using two registers only
Using three registers
Critical Analysis /Conclusion

Performance (15Marks) Viva


(5 Marks) Total/20

Pre-Lab Exercise /3

Performance /4

Results /3

Critical Analysis /2

Post Lab Exercise /3

Comments

You might also like