Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

CSC2201 Computer

Organization and Assembly


Language
Instructor Mr. Saqib Sadiq
Session Three Recap

• We talked about the x86 Processor Architecture,


• the Instruction Execution Cycle
• and the Basic Execution Environment
Session Four
Lesson Plan

• Instruction sets and types


• Basic elements of Assembly language
• Flow chart and top down-structured design
Instruction sets and types

• To command a computer’s hardware, you must speak its language. The


words of a computer's language are called instructions, and its vocabulary is
called an instruction set.
• This bring us to the stored-program concept (The idea that instructions and
data of many types can be stored in memory as numbers, leading to the
stored program computer)
Instruction sets and types

• Similarity between computer languages occurs because all computers are


constructed from hardware technologies based on similar underlying
principles
• And because there are a few basic operations that all computers must
provide.
Instruction sets and types

• How do we translate the following into AL?


X = 1 + 1;

• Answer
mov ax,1 ;move 1 to the AX register
add ax,1 ;add 1 to the AX register
Instruction sets and types

• Let us break it down


mov ax,1

• This is a data transfer instruction, with the following format


• MOV destination,source

destination source example


register register mov ax,bx
register immediate mov ax,10h
Instruction sets and types

• We used
• add ax,1

• Addition is an arithmetic instruction with the following format


• Add destination,source
destination source example
register immediate add ax,10
register register add ax,bx
Instruction sets and types

Notice the initial state of the register; also can you see how instructions were translated to
hexadecimal?
Instruction sets and types

We have now transferred the value 1 to the AX register; notice how IP (Instruction pointer) has
incremented
Instruction sets and types

We have now added the value 1 to the AX register; this register now has our solution
Session Four
Lesson Plan

• Instruction sets and types


• Basic elements of Assembly language
• Flow chart and top down-structured design
Basic elements of Assembly language

• Assembly language was designed to run in little memory and consists of


mainly low-level, simple operations.
• Then why does it have the reputation of being difficult to learn? After all,
how hard can it be to move data between registers and do a calculation?
Basic elements of Assembly language

• Becoming a skilled assembly language programmer requires a love of


details.
• You will find it helpful to build a foundation of basic information and
gradually fill in the details.
• It is similar to how a cook becomes a chef. They slowly build up their library
of recipes.
Basic elements of Assembly language

• So let’s get cooking!


• Previously we had talked about the different number systems present in an
assembly language program.
• We had said that any number ending with an h, d, or b was hexadecimal,
decimal or binary, respectively.
Basic elements of Assembly language

• These characters are an optional suffix you can append to your numbers and
are formerly known as a radix.
• If no radix is given, the integer constant is assumed to be decimal.
• Here are some examples using different radixes:
Basic elements of Assembly language
Basic elements of Assembly language

• Reserved words have special meaning in AL and can only be used in their correct
context.
• There are different types of reserved words:
• Instruction mnemonics, such as MOV, ADD, and MUL
• Register names
• Directives, which tell how to assemble programs
• Attributes, which provide size and usage information for variables and operands. Examples
are BYTE and WORD
• Operators, used in constant expressions
Basic elements of Assembly language

• An identifier is a programmer-chosen name. It might identify a variable, a


constant, a procedure, or a code label.
• Keep the following in mind when creating identifiers:
• They may contain between 1 and 247 characters.
• They are not case sensitive.
• The first character must be a letter (A..Z, a..z), underscore (_), @ , ?, or $. Subsequent
characters may also be digits.
• An identifier cannot be the same as an assembler reserved word.
Basic elements of Assembly language

Examples of valid identifiers


Basic elements of Assembly language

• We also make use of directives.


• One important function of assembler directives is to define program
sections, or segments
• The .DATA directive identifies the area of a program containing variables:
• The .CODE directive identifies the area of a program containing executable
instructions:
Basic elements of Assembly language

• Comments are an important way for the writer of a program to communicate


information about the program’s design to a person reading the source code.
• The following information is typically included at the top of a program listing:
• Description of the program’s purpose
• Names of persons who created and/or revised the program
• Program creation and revision dates
• Technical notes about the program’s implementation
Basic elements of Assembly language

• An instruction is a statement that becomes executable when a program is


assembled.
• Instructions are translated by the assembler into machine language bytes,
which are loaded and executed by the CPU at runtime.
Basic elements of Assembly language

• An instruction contains four basic parts:


• Label (optional)
• Instruction mnemonic (required)
• Operand(s) (usually required)
• Comment (optional)
• This is the basic syntax:
• [label:] mnemonic [operands] [;comment]
Basic elements of Assembly language

• A label is an identifier that acts as a place marker for instructions and data.
• A label placed just before an instruction implies the instruction’s address.
• Similarly, a label placed just before a variable implies the variable’s address.
Basic elements of Assembly language

• A label in the code area of a program (where instructions are located) must
end with a colon (:) character.
• Code labels are used as targets of jumping and looping instructions.
• For example, the following JMP (jump) instruction transfers control to the
location marked by a label.
Basic elements of Assembly language

• An instruction mnemonic is a short word that identifies an instruction.


• In English, a mnemonic is a device that assists memory. (e.g. BODMAS)
• Similarly, assembly language instruction mnemonics such as mov, add, and
sub provide hints about the type of operation they perform.
Session Four
Lesson Plan

• Instruction sets and types


• Basic elements of Assembly language
• Assembling, Linking, and Debugging
• Flow chart and top down-structured design
Flow chart and top down-structured design

• Design your program in term of procedures


• Have specifications that describe what the program needs to do
• Breakup the problem into small tasks
• Each procedure becomes a task
• Programs become easier to maintain and test in this manner
Flow chart and top down-structured design

• You can start with pseudocode


and than gradually add on details
to get a working program
• Flow charting can help you
visualize program flow
• Use flow charting software like
Microsoft VISIO to work with
flowchart shapes
Flow chart and top down-structured design
Flow chart and top down-structured design
Summary

• Today we talked about Instruction sets and types


• The Basic elements of Assembly language
• Flow chart and top down-structured design
Today’s practical

• Log into google classroom, navigate to classwork tab and click on the
tutorial label
• You should see a file labeled as lecture4.asm
• Download and run this file using emu8086. How does this program
demonstrate the basic elements of AL?
Assignment One

• Please see google classroom for details on how to complete first


assignment.
• We will go over instructions in class
Thanks

• Any questions?
• Feel free to reach out
• saqib.sadiq@szabist.pk

You might also like