MM Lab (252001173) Venu Gopal, Ece-B
MM Lab (252001173) Venu Gopal, Ece-B
MICROPROCESSORS
AND
MICROCONTROLLER
LAB
CLASS- ECE-B
Introduction to Keil
9.)
Write assembly language program to
perform Addition and Subtraction of
Multi-Byte 8/16 bit number using
keil software
ASSEMBLER
An assembler program is used to translate the assembly language mnemonics for
instructions to the corresponding binary codes. When you run the assembler, it reads the
source file of your program from the disk, where you saved it after editing on the first pass
through the source program the assembler determines the displacement of named data items, the
offset of labels and pails this information in a symbol table. On the second pass through the
source program, the assembler produces the binary code for each instruction and insertsthe
offset etc that is calculated during the first pass. The assembler generates two files on floppy
or hard disk. The first file called the object file is given the extension. OBJ. The object file
contains the binary codes for the instructions and information about the addresses of the
instructions. The second file generated by the assembler is called assembler list file. The list
file contains your assembly language statements, the binary codes for each instruction and
the offset for each instruction. In MASM/TASM assembler, MASM/TASM source file name
ASM is used to assemble the file. Edit source file name LST is used to view the list file,
which is generated, when you assemble the file.
LINKER
A linker is a program used to join several object files into one large object file and convert to an
exe file. The linker produces a link file, which contains the binary codes for all the combined
modules.
The linker however doesn't assign absolute addresses to the program, it assigns is said
to be reloadable because it can be put anywhere in memory to be run. In MASM/TASM,
LINK/TLIN5K source filename is used to link the file.
DEBUGGER
A debugger is a program which allows you to load your object code program into system
memory, execute the program and troubleshoot are debug it the debugger allows you to
look at the contents of registers and memory locations after your program runs. It allows
you to change the contents of register and memory locations after your program runs. It
allows you to change the contents of register and memory locations and return the
program. A debugger also allows you to set a break point at any point in the program. If you
inset a breakpoint the debugger will run the program up to the instruction where the
breakpoint is set and stop execution. You can then examine register and memory
contents to see whether the results are correct at that point. In MASM/TASM, td
filename is issued to debug the file.
DEBUGGER FUNCTIONS:
If there are any errors in the program assembler reports all of them at the command
prompt with line no's, if there are no bugs, you're ready to link the program.
To link the program, type the following line at DOSBox prompt.
Ex: link add.obj;
After linking you are ready to execute the program. To execute the program, type
the following command
Debug program name.exe hit the enter
Ex: Debug add.exe
Now you entered into the execution part of the program here you have to execute
the program. it'll execute that instruction and displays the contents of all the register.
You have to do this until you reach the last instruction of the program. After
execution you have to observe the results (in memory or registers based on what
you have written in the program).
Register Uses/Operations
.code segment
Keil C cross compiler: Keil is a German based Software development company. It provides
several development tools like
Keil Software provides you with software development tools for the 8051 family of
microcontrollers. With these tools, you can generate embedded applications for the multitude
of 8051 derivatives.
Keil provides following tools for 8051 development:
The keil 8051 tool kit includes three main tools like assembler, compiler and linker. These tools
have the following functions:
8051 project development cycle: These are the steps to develop 8051 project using keil
• Project workspace window: It is for showing all the related files connected with our
project.
• Editing window: It is the place where we will edit the code.
• Output window: It will show the output when you compile or build or run your project.
Target Selection
• Now we will be asked to choose your target device for which you want to write the
program.
• Scroll down the cursor and select generic from list. Expand the list and select 8051 (all
variants)
• When we click OK, we will be asked to add startup code and file to your project folder.
Click yes. Now on your screen expand target1 list fully. You will see following window.
• After that we have to add a file along with the appropriate file extension and then save it
to write the code in it.
EXPERIMENT: 1(A)
AIM: Write an Assembly Language Program for Addition. (8 bit).
Code segment
assume cs:code
start:
mov ah,0000h
mov si,3000h
mov al,[si]
Inc si
mov bl,[si]
add bl,al
inc si
mov [si],al
jc l1
inc si
mov[si],ah
Int 3
l1:
inc ahinc
si
mov[si],ah
code ends
end start
OUTPUT
PROGRAM:
inc si
inc si
mov[si],dx
int 3
l1:
inc dx
inc si
inc si
mov [si],dx
int 3
code ends
end start
Code window
Output
PROGRAM:
Code segment
assume cs: Code
start:
mov ah,0000h
mov si,3000h
mov al,[si]
inc si
mov bl,[si]
sub al, bl
inc si
mov [si],al
jc l1
inc si
mov[si], ah
int 3
l1:
inc ah
inc si
mov [si], ah
int 3
code ends
end start
code window:
Output:
Program
code segment
start:
mov ax,0000h
movbx,ax
mov dx,ax
mov si,3000h
movax,[si]
inc si
inc si
mov bx,[si]
inc si
inc si
sub ax,bx
mov [si],ax
jc l1
inc si
inc si
mov[si],dx
int 3
l1:inc dx
inc si
inc si
mov[si],dx
int 3
code ends
end start
Code window:
Output
PROGRAM:
Code segment
Assume cs:code
Start:
Mov si,3000h
Mov al,[si]
Inc si
Mov bl,[si]
Mul b1
Inc si
Mov[si],ax
Int 3
Code ends
End start
CODE WINDOW:
OUTPUT:
OUTPUT
PROGRAM:
code segment
start :
mov ax,0000h
mov bx,ax
mov si,3000h
mov al,[si]
inc si
mov bl ,[si]
div b1
inc si
mov[si],ax
int 3
code ends
end start
CODE WINDOW:
OUTPUT:
OUTPUT WINDOW
Result:- Two numbers are divided using Assembly Language program and
executed.
EXPERIMENT: 4(A)
PROGRAM:
Cod segment
Assume cs:code
Start:
Mov ax,0000h
Mov bl,al
Mov cl,al
Mov si,1000h
Mov bl,[si]
Dec b1
Mov cl,bl
Mov si,2000h
L2:mov al,[si]
Cmp al,[si+1]
Jge l1
Xchg al,[si+1]
Mov [si],al
L1:inc si
Loop l2
Int 3
Code ends
End start
Code window:
OUTPUT:
PROGRAM:
Code segment
Assume cs:code
Start:
Mov ax,0000h
Mov bl,al
Mov cl,bl
Mov si,1000h
Mov bl,[si]
Dec b1
Mov cl,b1
Mov si,2000h
L2:mov al,[si]
Cmp al,[si+1]
Jle l1
Xchg al,[si+1]
Mov [si],al
L1:inc si
Loop l2
Int 3
Code ends
End start
CODE WINDOW:
OUTPUT:
PROGRAM:
code segment
assume cs:code
start:
mov ax,0000h
mov bl,al
mov cl,bl
mov si,1000h
mov bl,[si]
dec b1
l3:mov cl,bl
mov si,7071h
l2:mov al,[si]
cmp al,[si+1]
jle l1
xchg al,[si+1]
mov [si],al
l1:inc si
loop l2
dec bl
jnz l3
code ends
end start
OUTPUT:
PROGRAM:
Code segment
Assume cs:code
Start:
Mov ax,0000h
Mov bl,al
Mov cl,bl
Mov si,1000h
Mov bl,[si]
Dec bl
L3:mov c1,bl
Mov si,3000h
L2:mov al,[si]
Cmp al,[si+1]
Jge l1
Xchg al,[si+1]
Mov [si],al
L1:inc si
Loop l2
Dec bl
Jnz l3
Int 3
Code ends
End start
CODE WINDOW:
OUTPUT:
PROGRAM:
//addition
mov a,#40h
mov b,#20h
add a,b
mov r0,a
mov 44h,a
//subtraction
mov a,#40h
mov b,#20h
subb a,b
mov r1,a
mov 45h,a
//multiplication
mov a,#40h
mov b,#20h
mul ab
mov r2,a
mov r3,b
mov 46h,a
mov 47h,b
//division
mov a,#40h
mov b,#20h
div ab
mov r4,a
mov r5,b
mov 48h,a
mov 49h,b
end
CODE WINDOW:
OUTPUT:
AIM: Write an Assembly Language Program for logic instructions i.e., and, or, xor and
complement of 8/16-bit numbers Using KEIL software
PROGRAM:
//and operation
mov a,#40h
mov r0,#20h
anl a,r0
mov r1,a
mov 44h,a
//or operation
mov a,#40h
mov r2,#20h
orl a,r2
mov r3,a
mov 45h,a
//xor operation
mov a,#40h
mov r4,#20h
xrl a,r4
mov r5,a
mov 46h,a
//cmpl operation
mov a,#40h
cpl a
mov r6,a
mov 47h,a
end
CODE WINDOW:
OUTPUT :
Result: Logic instructions i.e., and, or, xor and complement of 8/16-bit numbers
Using KEIL software were performed using Assembly Language program and
executed.
EXPERIMENT: 9
AIM: To write assembly language program using Using KEIL software to perform
Multi byte addition and subtraction .
PROGRAM:
//addition
mov a,#20h
mov r0,#10h
add a,r0
mov r1,a
mov 44h,a
mov a,#40h
mov r2,#20h
add a,r2
mov r3,a
mov 45h,a
//subtraction
mov a,#20h
mov r4,#10h
subb a,r4
mov r5,a
mov 46h,a
mov a,#40h
mov r6,20h
subb a,r6
mov r7,a
mov 47h,a
end
CODE WINDOW :
OUTPUT:
Program:
// ALP to transfer data from ROM memory
org 0000h
mov @ r0,a
inc dptr
inc r0
clr a
djnz r7,back
org 600h
end.
CODE WINDOW :
OUTPUT :