Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Lecture 9 Programming

The document is a lecture on programming the basic computer, focusing on assembly language and its components, including binary, octal, hexadecimal, and symbolic code. It explains the structure of assembly language programs, the role of the assembler, and provides an example of a multiplication program using assembly language. The lecture emphasizes the importance of understanding machine instructions and the translation process from symbolic to binary code.

Uploaded by

huzaifaaakhalid
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 9 Programming

The document is a lecture on programming the basic computer, focusing on assembly language and its components, including binary, octal, hexadecimal, and symbolic code. It explains the structure of assembly language programs, the role of the assembler, and provides an example of a multiplication program using assembly language. The lecture emphasizes the importance of understanding machine instructions and the translation process from symbolic to binary code.

Uploaded by

huzaifaaakhalid
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Computer Organization & Assembly Language

Lecture-9
Programming the Basic Computer

Dr. Imtiaz Hussain


Professor
Department of Electrical and Computer Engineering
Iqra University, Karachi, Pakistan
email: imtiaz.hussain@iqra.edu.pk

Spring 2024
1
Today
• Introduction

• Assembly Language

• Control functions

• Example Problems
Introduction
• Programs written for a computer may be in one of the following
categories:

1. Binary code. This is a sequence of instructions and operands in


binary that list the exact representation of instructions as they
appear in computer memory.

2. Octal or hexadecimal code. This is an equivalent translation of the


binary code to octal or hexadecimal representation.

3. Symbolic code. The user employs symbols (letters, numerals, or


special characters) for the operation part, the address part, and
other parts of the instruction code. Each symbolic instruction can
be translated into one binary coded instruction. This translation is
done by a special program called an assembler.
Introduction
• Programs written for a computer may be in one of the
following categories:

4. High-level programming languages. These are special


languages developed to reflect the procedures used in
the solution of a problem rather than be concerned
with the computer hardware behavior.
Introduction
Introduction
• Consider the binary program listed in Table below.

• The first column gives the memory location of each


instruction or operand.

• The second column lists the binary content of these


memory locations.
Introduction
• The program can be stored in the indicated portion of
memory, and then executed by the computer starting from
address 0.

• The hardware of the computer will execute these


instructions and perform the intended task.
Introduction
• However, a person looking at this program will have a
difficult time understanding what is to be achieved when
this program is executed.

• Nevertheless, the computer hardware recognizes only this


type of instruction code.
Introduction
• Writing 16 bits for each instruction is tedious because there are too
many digits.
• We can reduce the number of digits per instruction if we write the
octal equivalent of the binary code. This will require six digits per
instruction.
• On the other hand, we can reduce each instruction to four digits if we
write the equivalent hexadecimal code as shown in following table.
Assembly Language
• Rules of the Language: Each line of an assembly language
program is arranged in three columns called fields. The fields
specify the following information.
1. The label field may be empty, or it may specify a symbolic
address.
2. The instruction field specifies a machine instruction or a pseudo
instruction.
3. The comment field may be empty, or it may include a comment.
Assembly Language
• Symbolic Address: It consists of one, two, or three, but not
more than three alphanumeric characters.
– The first character must be a letter; the next two may be letters or
numerals.
– The symbol can be chosen arbitrarily by the programmer.
– A symbolic address in the label field is terminated by a comma so
that it will be recognized as a label by the assembler
Assembly Language
• Instruction Field: The instruction field in an assembly
language program may specify one of the following items:

1. A memory-reference instruction (MRI)


2. A register-reference or input-output instruction (non-MRI)
3. A pseudo instruction with or without an operand
Assembly Language
• Instruction Field: The instruction field in an assembly
language program may specify one of the following items:

1. Memory-Reference Instruction (MRI):


– MRI occupies two or three symbols separated by spaces.
– The first must be a three-letter symbol defining an MRI
operation code.
– The second is a symbolic address.
– The third symbol, which may or may not be present, is the
letter I.
– If I is missing, the line denotes a direct address instruction.
The presence of the symbol I denotes an indirect address
instruction.
Assembly Language
• Instruction Field: The instruction field in an assembly
language program may specify one of the following items:

2. Non-MRI:
– A non-MRI is defined as an instruction that does not have
an address part.
Assembly Language
• Instruction Field: The instruction field in an assembly
language program may specify one of the following items:

3. Pseudoinstruction:
– A pseudoinstruction is not a machine instruction but rather
an instruction to the assembler giving information about
some phase of the translation.
– Four pseudoinstructions that are recognized by the
assembler are listed below.
Assembly Language
• Comments Field: The third field in a program is reserved for
comments. A line of code may or may not have a comment, but if
it has, it must be preceded by a slash for the assembler to
recognize the beginning of a comment field.
• Comments are inserted for explanation purposes only and are
neglected during the binary translation process.
Example-1
• The first line has the pseudoinstruction ORG to define the origin of
the program at memory location (100)16.

• The next six lines define machine instructions, and the last four
have pseudoinstructions.
Example-1
• Three symbolic addresses have been used and each is listed in
column 1 as a label and in column 2 as an address of a memory-
reference instruction.
• Three of the pseudoinstructions specify operands, and the last one
signifies the END of the program.
Example-1
• When the program is translated into binary code and executed by
the computer it will perform a subtraction between two numbers.

• The subtraction is performed by adding the minuend to the 2's


complement of the subtrahend.
Example-1
• The subtrahend is a negative number. It is converted into a binary
number in signed-2's complement representation because we
dictate that all negative numbers be in their 2's complement form.

• When the 2's complement of the subtrahend is taken (by


complementing and incrementing the AC), -23 converts to +23 and
the difference is 83 + (2's complement of -23) = 83 + 23 = 106.
Example-1
• Translation to Binary: The translation of the symbolic program
into binary is done by a special program called an assembler.
The Assembler

• An assembler is a program that accepts a symbolic


language program and produces its binary machine
language equivalent.

• The input symbolic program is called the source


program and the resulting binary program is called
the object program.

• The assembler is a program that operates on


character strings and produces an equivalent binary
interpretation.
The Assembler

• Representation of Symbolic Program in Memory:


The Assembler
• A line of code is stored in consecutive memory locations
with two characters in each location. Two characters can be
stored in each word since a memory word has a capacity of
16 bits
The Assembler
Programming Arithmetic and Logic Operations
• Some computers have machine instructions to add,
subtract, multiply, and divide.

• Others, such as the basic computer, have only one


arithmetic instruction, such as ADD.

• Operations not included in the set of machine instructions


must be implemented by a program.
Multiplication Program
• We now develop a program for multiplying two numbers.
• To simplify the program, we neglect the sign bit and assume
positive numbers.
• We also assume that the two binary numbers have no more
than eight significant bits so their product cannot exceed the
word capacity of 16 bits.
Multiplication
Program
• Location X holds the
multiplicand and location Y
holds the multiplier.

• A counter CTR is set to -8


and location P is cleared to
zero.
Multiplication
Program
• The program has a loop that
is traversed eight times,
once for each significant bit
of the multiplier.
Multiplication
Program
• The multiplier bit can be
checked if it is transferred to
the E register.
• This is done by clearing E,
loading the value of Y into
the AC, circulating right E and
AC and storing the shifted
number back into location Y.
• This bit stored in E is the low-
order bit of the multiplier.
Multiplication
Program
• The multiplier bit can be
checked if it is transferred to
the E register.
• This is done by clearing E,
loading the value of Y into
the AC, circulating right E and
AC and storing the shifted
number back into location Y.
• This bit stored in E is the low-
order bit of the multiplier.
Multiplication
Program
• We now check the value of
E.
• If it is 1, the multiplicand X
is added to the partial
product P.
• If it is 0, the partial product
does not change.
Multiplication
Program
• We then shift the value of X
once to the left by loading it
into the AC and circulating
left E and AC.
Multiplication
Program
• The loop is repeated eight
times by incrementing
location CTR and checking
when it reaches zero.

• When the counter reaches


zero, the program exits
from the loop with the
product stored in location P.
Multiplication Program
END OF LECTURE-9

You might also like