∙ 1ECH 492 111101100
∙ FA98 64152 1111101010011000
6. Convert the decimal number 1625 to: Hexadecimal, Octal and Binary.
Hexadecimal Octal Binary
659 3131 11001011001
7. What is the purpose of an Assembler?
The assembler checks the typographical errors and validity of the instructions used in the assembler program.It does not check the logical error of the program.
8. What is the purpose of a debugger?
The debugger proves that a program is working correctly or not.
9. What are the steps in Developing a program?
Given a task Analyze the task Develop a flowchart Code program
Edit to enable the program Compile/Assemble to translate into machine code
Use the debugger to test the step to the program Document
10. A microprocessor / Microcontroller instructions are classified as one, two or three
cycles instructions, explain what this mean?
Every instruction takes a certain time to execute the number of cycles ,represent the time it takes for the instruction to execute completely.
11. Use the instruction set provided for the Intel 8051 series of microcontrollers,
perform a hand assembly of the following program:
START: MOV A,#05H 74,05
MOV B, #04H 75,04
MOV R0, B A8
LOOP: ADD A, B 25
DJNZ R0, LOOP D8
END
Develop a flowchart for the above program, and explain what the program does.
Initially we store 5H in A and 4H in B then the program add the contents of A,B until R0 reaches the value of 0.
Flowchart for the above program
The result is 15H OR 21.
Task 2
Part i:
Development of Some Simple Assembly Language Programs
Write a program to determine the factorial of a given number stored in register A.
The result is 18H OR 24.
Question 1:
What is maximum integer number that the above program provides a satisfactory
result?
For N=4 Answer =4*3*2*1=24
N=5 Answer=5*4*3*2*1=120
N=6 Answer=6*5*4*3*2*1=720
When N=6 ,the result is expected in above 255 which in the maximum decimal number that can be placed in an 8 bit register so N=5 is the maximum.
Question 2:
How is it possible to modify the program to increase the range of numbers?
The program needs to be modified to handle 16 bit multiplication rather than using the “MUL” they can only handle A*B.
RevisionsQuestions and Tutorials
1. What are the purpose(s) of addressing Modes in microcontrollers?
The addressing modes enable the program to read and write from into memory location.
For example to move data from one place and place it in another.
2. List some of the addressing modes of the Intel 8051 processors and give an
example.
Direct Addressing: MOV A,20H
Indirect Addressing: MOV R0,#20H
MOV A,@R0
Immediate Addressing:MOV A,#05
3. What is the purpose of the program counter?
The program counter holds the address( lines number) of the next instruction that the process must execute at start ,program counter (PC) is loaded with 0000H (it is 16 bit register) therefore the processor executes the instruction in address 0000H.
4. Explain what the Intel 8051 processor performs when it is first switched ON or
reset.
When the processor is first switched ON, the program counter as well as the rest of registers become cleared to Zero.Therefore the processor then looks at the program counter(0000H) and begins to execute the instructions in this address.
5. Draw a block diagram representation of a simple 8051-based Microcontroller
based system.
Part II: Assembly Language Program Development
Part II - Problem 1: Fibonacci Numbers
The first 10 Fibonocci numbers as illustrated below when the first two numbers are 1
and 1.
1, 1, 2, 3, 5, 8, 13, 21, …
the next numbers are generated by adding the last two numbers together.
So the next number in the above series is 13+21=34 and so on.
For example if we initially placenumber 2 in location 20H and number 4 in location 21H then the program should
generate:2, 4, 6, 10, 16, 26,42
The program to generate the series: :2, 4, 6, 10, 16, 26,42
(These are 2H, 4H, 6H, 0AH, 10H, 1AH, 2AH respectively in hexadecimal)
Develop a program to generate the next 6 Fibonocci numbers given that the first two
numbers are stored in locations 30H and 31H. For example if we initially place
number 15H in location 30H and number 22Hin location 31H then the program should
generate:15H,22H,37H,59H,90H,E9
The program to generate the series: 15H,22H,37H,59H,90H,E9
(These are 21,34,55,89,144 and 233 respectively in decimal)
Question
Modify the program so that it will automatically check if the number is small
enough to store in a memory location
When we consider this program the next number be
Should be 120H (288) but this is higher than FFH(255)
Therefore the carry sets to 1.
Part II - Problem 2: Filling and Copying Memory Blocks
Filling Memory Blocks
This program fills the memory location from 20H to
2FH.
It fills the numbers from 0FH-1H.
Copying Memory Blocks
Initially we have to fill with random numbers from location 20H to 2FH
This program copies the contents of memory location
20H-2FH into locations 40H-4FH.
Part II - Problem 3: Sorting Numeric Data
Write a program to sort numbers stored in memory locations 20H to 2FH in
Descending order ,if locations 20H to 2FH contains:
5,7,8,1,2,9,11,12,34,15,65,23,31,3,6,4
Then the program should rearrange the numbers to give:
65,34,31,23,15,12,11,9,8,7,6,5,4,3,2,1
Initially we have to fill with random numbers from location 20H to 2FH
Question
Modify the program so that it will sort the numbers in ascending order (i.e. Increasing
order).
If locations 20H to 2FH contains:
5,7,8,1,2,9,11,12,34,15,65,23,31,3,6,4
Then the program should rearrange the numbers to give:
1,2,3,4,5,6,7,8,9,11,12,15,23,31,34,65
Initially we have to fill with random numbers from location 20H to 2FH
Part III - Problem 4: Simulation of a 24-Hour Alarm
Clock
The task is here is to write an assembly language program that simulates the function
of a 24-hour Alarm Clock.
The program starts by incrementing (adding 1) to the Seconds (i.e. memory location
22H) until it reaches 60H, at which point it should reset seconds to 00 and add a ‘1’
to the minutes (i.e. memory location 21H). If minutes reach 60H, it should reset
minutes to 00 and add a ‘1’ to hours (i.e. memory location 20H). Once hours reach to
24, it should reset it to 00 and start the process over and over again.