Вы находитесь на странице: 1из 16

1

Government College Daggar Buner


The affiliated college of
The University OF Swat

Assignment

Computer Organization and Assembly


Language
Submitted to
Lecturer in computer science
Arshad sir
Submitted by
Nasib Zada Roll #1787076

On ____/____________/___________
2

Programming
Programming in the sense of Microcontrollers (or any computer)
means writing a sequence of instructions that are executed by the
processor in a particular order to perform a predefined task.

The three levels of Programming Languages are:

 Machine Language

 Assembly Language

 High-level Language

Machine language is the language directly understood by the


computer and the performance is very high, but the problem is that
it’s too difficult to write programs in Machine Language.

High Level languages are languages that are relatively easy for
a human to understand keeping a particular syntax in mind. High
level languages must first be converted to Machine language to be
ready to execute on the machine.

Assembly Language
The Assembly Language is often called middle level language.

This is a low-level but, relatively easier than Machine language


for a human to understand and write code in.

The assembly programming language is a low-level language


which is developed by using mnemonics. The microcontroller or
microprocessor can understand only the binary language like 0's or
1's therefore the assembler convert the assembly language to binary
language and store it in the memory to perform the tasks.
3
4

Today, assembly language is specially used for direct hardware


manipulation, access to specialized processor instructions, or to
address critical performance issues. Typical uses are device drivers,
low-level embedded systems.

Structure of assembly language program

.model small Model: defines the size of


data and code a program
.stack 100h
can have.
.data
Stack: block of memory for
.code stack.
Main proc Data segment: in data
….. segment all variables are
declared and initialized.[ DS ]
….. is data segment register.
Main endp Code sgmt: this segment
End main contains the program
instructions.[ csr ]

Registers: a register is a very small amount of very fast memory that is


built into the processor. These are used to store data temporarily
during the execution.

There are two types of registers

1. General purpose register: registers that a programmer can use


during the program execution.
2. Special purpose registers: used by the processor on its own terms
for its own usage.
5

Addressing modes:

Direct Addressing mode:


Mov Ax, #af984d

Register Addressing mode:


Mov Ax, Bx

Indirect Addressing mode:


Mov Ax, [Bx]

Instruction Set
Is the set of all possible input/functions that CPU supports.
For example, addition, multiplication, subtraction, division,
comparison etc.
Instruction contains OPERATION CODE+ OPERAND CODE
Mov ax, bx
Mov is op-code
Ax,bx is operand code
6

Assembly language
Write a program to add/
Write a program to print
subtract two numbers
“I love pakistan” .
.model small
Mov al, 4h
.data
Mov bl, 4h
Var1 DB 10, 13, ‘I love Pakistan$’
Add al, bl
.code
Add al, 30h ;sub for subtraction
Main proc
Mov dl, al
Mov ax, @data
Mov ah, 2h
Mov ds, ax
Int 21h
Mov dx, offset var1

Mov ah, 9h

Int 21h

Main endp

End main
7

Write a program for division Write a program to multiply


two numbers.
mov ax, 6h

mov bx, 3h
mov ax, 2h
div bx
mov bx, 3h
mov dx, ax
mul bx
add dx, 30h
mov dx, ax
mov ah, 2h
add dx, 30h
int 21h
mov ah, 2h

int 21h

Program to add two numbers and print the result

mov ax, 4

mov bx, 3

add ax, bx

add ax, 48

mov dx, ax

mov ah, 2h

int 21h
8

PROGRAM TO TAKE AN INPUT CHARACTER AND PRINT THAT


CHARACTER

mov ah, 1h ;take input and store it in ax

int 21h ;interrupt

mov dx, ax ;must be in dx in order to be printed

mov ah, 2h

int 21h

Control Structure of Assembly Language


a statement that controls the execution of the
program is called control structure/statement.

1. Unconditional control
Interrupting linear execution
unconditionally is known as Unconditional
control structure.
The common control for it is JMP
Example
.model small
.stack 100h
.data
9

msg DB "label called$"


.code
main proc
mov ax, @data
mov ds, ax

label:
mov dx, offset msg
mov ah, 9h
int 21h

jmp label

main endp
end main

;this program will call the label for an


infinite number of times because there is
no condition on which the jumping
should stop.
10

2. Conditional control structure/statement


The statement that controls the execution of
a program according to a given condition is
called Conditional control structure.
Normally, we compare two variables or
registers and then proceed with the
condition based on the comparing result. i.e
if EQUAL, GREATER THAN, LESS THAN, GREATER
OR EQUAL, LESS OR EQUAL, EQUAL AND
ZERO, EQUAL AND NOT ZERO, NOT EQUAL
etc.

JE - jump if equal
JL -jump if less
JB -jump if below
JG - jump if greater
JA -jump if above
JGE -jump if greater or equal
JLE -jump if less or equal
JNE -jump if not equal
11

PROGRAM TO EXECUTE A BLOCK OF CODE if


Bx and Cx are equal
.model small
.stack 100h
.data
msg DB "the conditio is true$"
.code
main proc
mov ax, @data
mov ds, ax
mov cx, 5
mov bx, 5
cmp bx, cx
je label ; jump if the above comparison give equal result

label:
mov dx, offset msg
mov ah, 9h
int 21h
12

#Program
Mov ax, 10
Mov bx, 9
Cmp ax, bx
JG label

Label:
mov dx, 1h
add dx, 30h
mov ah, 2h
int 21h
;this program jumps to label if the value in Ax is
greater than the value in bx.
13

#PROGRAM
Mov ax, 4
Mov bx, 6
Cmp ax, bx
JL label

Label:
mov dx, 1h
add dx, 30h
mov ah, 2h
int 21h
;This program jumps to label if the value of ax is
less than the value in bx
14

#PROGRAM
Mov ax, 10
Mov bx, 9
Cmp ax, bx
JGE label

Label:
mov dx, 1h
add dx, 30h
mov ah, 2h
int 21h
;This program jumps if the value in AX is
greater than or equal to the value in BX.
15

#PROGRAM
Mov ax, 1
Mov bx, 6
Cmp ax, bx
JLE label

Label:
mov dx, 1h
add dx, 30h
mov ah, 2h
int 21h
;this program jumps to label if the value
of Ax is less than or equal to the value in Bx.
16

#PROGRAM
Mov ax, 10
Mov bx, 9
Cmp ax, bx
JNE label

Label:
mov dx, 1h
add dx, 30h
mov ah, 2h
int 21h
;This program jumps to label if the Ax and Bx are
not equal.

Вам также может понравиться