Академический Документы
Профессиональный Документы
Культура Документы
Assignment
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.
Machine Language
Assembly Language
High-level 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.
Addressing modes:
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
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
mov ax, 4
mov bx, 3
add ax, bx
add ax, 48
mov dx, ax
mov ah, 2h
int 21h
8
mov ah, 2h
int 21h
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
label:
mov dx, offset msg
mov ah, 9h
int 21h
jmp label
main endp
end main
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
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.