0% found this document useful (0 votes)
11 views

Theory Lecture Week 6M MES Prof Muhibul

Uploaded by

Asifur R. Himel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Theory Lecture Week 6M MES Prof Muhibul

Uploaded by

Asifur R. Himel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Lecture # 06M:

Assembly Language
Programming for
ATmega328P

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE
American International University-Bangladesh (AIUB)
Dhaka, Bangladesh
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Outline
❑Arduino AVR Architecture
❑Assembly Language Programming
❑Examples of Assembly Programming
❑Flow Chart Drawing and Algorithm Development

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 2 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


AVR Architecture of CPU
▪ Arithmetic Logic Unit (ALU)
▪ 32 General Purpose Register (GPR)
 each 8-bit
▪ Program Counter (PC)
▪ Instruction Decoder
▪ Status Register (SREG)

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 3 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


AVR Flags/Status Register
❑ C = Carry Flag, This flag is set whenever there is a carry out from the D7 bit after an arithmetic
operation(Addition, subtraction, increment, decrement, etc.). This flag bit is affected after an 8-
bit addition or substruction.
❑ Z = Zero Flag, This flag is affected after an arithmetic or logic operation. If the result is zero

Status
than Z = 1, else Z = 0.
❑ N = Negative Flag, It reflects the result of an arithmetic operation. If the D7 bit of the result is
Register
zero, then N = 0 and the result is positive. Else N = 1 and the result is negative.
❑ V = Overflow Flag,
❑ S = Sign Flag,
❑ H = Half Carry Flag, this bit is set if there is a carry from D3 to D4 bit after ADD or SUB
instruction.
❑ T = Bit Copy Storage. Used as a temporary storage for bit. It can be used to copy a bit from a
GPR to another GPR.
❑ I = Global Interrupt Enable
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 4 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Direct Data Register Method
❑ To assign input- 0 PORTB Register
❑ To assign output- 1 PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0

❑ DDRB= 0x 05; 0 0 0 0 0 0 0 1

❑ Or DDRB= 0b 00000101; PB0 and PB2 are


output pin while rest are input.
DDRB Register
❑ To write High-1
PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0
❑ To write Low-0
0 0 0 0 0 1 0 1
❑ PORTB= 0x01;
❑ PORTB= 0b00000001; write PB0 as high.

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 5 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Instruction Set Summary
Mnemonics Operands Description Operations Flags Clocks
ADD Rd,Rr Add two Registers Rd ← Rd + Rr Z,C,N,V,H 1
ADC Rd,Rr Add with Carry two Registers Rd ← Rd + Rr + C Z,C,N,V,H 1
SUB Rd,Rr Subtract two Registers Rd ← Rd - Rr Z,C,N,V,H 1
SUBI Rd,K Subtract Constant from Register Rd ← Rd - K Z,C,N,V,H 1
AND Rd,Rr Logical AND Registers Rd ← Rd • Rr Z,N,V 1
OR Rd,Rr Logical OR Registers Rd ← Rd V Rr Z,N,V 1
NEG Rd Two’s Complement Rd ← 0x00 - Rd Z,C,N,V,H 1
INC Rd Increment Rd ← Rd + 1 Z,N,V 1
DEC Rd Decrement Rd ← Rd - 1 Z,N,V 1
MUL Rd,Rr Multiply Unsigned R1:R0 ← Rd x Rr Z,C 2
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 6 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED Instruction Set Summary


Mnemonics Operands Description Operations Flags Clocks
TST Rd Test for Zero or Minus Rd ← Rd • Rd Z,N,V 1
CLR Rd Clear Register Rd ← Rd ⊕ Rd Z,N,V 1
MOV Rd, Rr Move Between Registers Rd ← Rr None 1
LDI Rd, K Load Immediate Rd ← K None 1
LDS Rd, K Load Direct from data space location K Rd← [K] None 1
IN Rd, P From In Port P/ address to Rd register Rd ← P None 1
OUT P, Rr From Rr register to Out Port P/ address P ← Rr None 1
PUSH Rr Push Register on Stack STACK ← Rr None 2
POP Rd Pop Register from Stack Rd ← STACK None 2
NOP No Operation None 1
BREAK Break For On-chip Debug Only None N/A
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 7 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Instruction Set Summary
Mnemonics Operands Description Operations Flags Clocks
STS K, Rr Store Rr to data space location K. [K] ← Rr None 1
Sets the b no. bits of the A
SBI A, b Sets a specified bit in an I/O Register None 1
register
Resets a specified bit in an I/O Resets the b no bits of the
CBI A, b None 1
Register A register
Skip if Bit in I/O Register is Cleared/ If b no bit of A register is 0,
SBIC A, b None 1
Reset then skip PC by 2 or 3.

If b no bit of A register is 1,
SBIS A, b Skip if Bit in I/O Register is set None 1
then skip PC by 2 or 3.

RJUMP K Relative jump PC← PC+K+1 None 1

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 8 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Memory Locations

STS 0x60, R0

LDS R31, 0x01FF

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 9 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Register Contents
SBI DDRB, 3; SBIC R7, 5;
DDRB Register R7 Register
PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0 8 7 6 5 4 3 2 1
0 0 0 0 0 1 0 0 1 1 1 0 1 1 1 1

PC = PC+2 or 3
CBI DDRB, 5;
DDRB Register SBIS R8, 5;
PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0 R8 Register
0 0 0 0 0 0 0 0 8 7 6 5 4 3 2 1
1 1 1 1 1 1 1 1
PC = PC+2 or 3
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 10 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Programming Examples
Example: State the contents of R20, R21, and data memory Example: State the contents of RAM locations of
$212, $213, $214, $215, and $216 after executing
location of 0x120 after executing the following program. the following program.
LDI R20, 5; Solution: LDI R16, 0x99
LDI R21, 2; LDI R20, 5; R20=5 STS 0x212, R16
ADD R20,R21; LDI R21, 2; R21=2 LDI R16, 0x85
ADD R20,R21; ADD R20, R21; R20=5+2=7 STS 0x213, R16 Solution:
STS 0x120, R20; ADD R20, R21; R20= 7+2=9 LDI R16, 0x3F 0x212 0x99
STS 0x120, R20; 0x120 = 9 STS 0x214, R16
0x213 0x85
LDI R16, 0x63
R20= 9 0x214 0x3F
STS 0x215, R16
R21= 2 0x215 0x63
LDI R16, 0x12
0x120= 9 0x216 0x12
STS 0x216, R16
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 11 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED

Difference Between Assembly and C


Assembly Code Example
sei ; set Global Interrupt Enable
sleep; enter sleep, waiting for interrupt
; note: will enter sleep before any pending interrupt(s)
C Code Example
__enable_interrupt(); /* set Global Interrupt Enable */
__sleep(); /* enter sleep, waiting for interrupt */
/* note: will enter sleep before any pending interrupt(s) */

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 12 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


EEPROM Control Register (EECR)

7 6 5 4 3 2 1 0
EEPM(1:0) EERIE EEMPE EEPE EERE

SBIC EECR, EEPE; If EEPE bit of EECR is 0 then the Program


Counter (PC) will skip 2 or 3 steps.

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 13 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED

Difference Between Assembly and C


Assembly Code Example C Code Example
EEPROM_write: void EEPROM_write(unsigned int uiAddress,
; Wait for completion of previous write unsigned char ucData)
sbic EECR,EEPE {
rjmp EEPROM_write /* Wait for completion of previous write */
; Set up address (r18:r17) in address register while(EECR & (1<<EEPE))
out EEARH, r18 ;
out EEARL, r17 /* Set up address and Data Registers */
; Write data (r16) to Data Register EEAR = uiAddress;
out EEDR,r16 EEDR = ucData;
; Write logical one to EEMPE /* Write logical one to EEMPE */
sbi EECR,EEMPE EECR |= (1<<EEMPE);
; Start eeprom write by setting EEPE /* Start eeprom write by setting EEPE */
sbi EECR,EEPE EECR |= (1<<EEPE);
ret }
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 14 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Functions of Assembly and C
The next code examples Assembly Code Example C Code Example
show assembly and C EEPROM_read: unsigned char
functions for reading the ; Wait for completion of previous write EEPROM_read(unsigned int uiAddress)
EEPROM. sbic EECR,EEPE {
rjmp EEPROM_read /* Wait for completion of previous write */
; Set up address (r18:r17) in address while(EECR & (1<<EEPE))
The examples assume register ;
that interrupts are out EEARH, r18 /* Set up address register */
controlled so that no out EEARL, r17 EEAR = uiAddress;
interrupts will occur ; Start eeprom read by writing EERE /* Start eeprom read by writing EERE */
during the execution of sbi EECR,EERE EECR |= (1<<EERE);
; Read data from Data Register /* Return data from Data Register */
these functions. in r16,EEDR return EEDR;
ret }

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 15 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Functions of Assembly and C
Bit 0 – IVCE: Interrupt Vector Change Enable
The IVCE bit must be written to logic one to enable change of the IVSEL bit. IVCE is cleared by hardware
four cycles after it is written or when IVSEL is written. Setting the IVCE bit will disable interrupts,
Assembly Code Example C Code Example
Move_interrupts:
; Enable change of Interrupt
Vectors void Move_interrupts(void)
ldi r16, (1<<IVCE) {
out MCUCR, r16 /* Enable change of Interrupt Vectors */
; Move interrupts to Boot Flash MCUCR = (1<<IVCE);
section /* Move interrupts to Boot Flash section */
ldi r16, (1<<IVSEL) MCUCR = (1<<IVSEL);
out MCUCR, r16 }
ret

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 16 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Functions of Assembly and C
The assembly code example returns the TCNT1 value in the r17:r16 register pair.
If an interrupt occurs between the two instructions accessing the 16-bit register, the interrupt code
updates the temporary register by accessing the same or any other of the 16-bit Timer Registers, then the result
of the access outside the interrupt will be corrupted. Therefore, when both the main code and the interrupt code
update the temporary register, the main code must disable the interrupts during the 16-bit access.
Assembly Code Example C Code Example
; Set TCNT1 to 0x01FF
ldi r17,0x01 unsigned int i;
ldi r16,0xFF ...
out TCNT1H,r17 /* Set TCNT1 to 0x01FF */
out TCNT1L,r16 TCNT1 = 0x1FF;
; Read TCNT1 into r17:r16 /* Read TCNT1 into i */
in r16,TCNT1L i = TCNT1;
in r17,TCNT1H ...
...
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 17 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Functions of Assembly and C
The following code examples Assembly Code Example C Code Example
show how to do an atomic read of uunsigned int TIM16_ReadTCNT1( void )
TIM16_ReadTCNT1: {
the TCNT1 Register contents. ; Save global interrupt flag unsigned char sreg;
in r18,SREG unsigned int i;
Reading any of the OCR1A/B or ; Disable interrupts /* Save global interrupt flag */
cli sreg = SREG;
ICR1 Registers can be done by ; Read TCNT1 into r17:r16 /* Disable interrupts */
using the same principle in r16,TCNT1L _CLI();
in r17,TCNT1H /* Read TCNT1 into i */
; Restore global interrupt flag i = TCNT1;
out SREG,r18 /* Restore global interrupt flag */
ret SREG = sreg;
return i;

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 18 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Functions of Assembly and C
The assembly code example Assembly Code Example C Code Example
returns the TCNT1 value in unsigned int TIM16_ReadTCNT1( void )
TIM16_ReadTCNT1:
the r17:r16 register pair. ; Save global interrupt flag {
in r18,SREG unsigned char sreg;
The following code ; Disable interrupts unsigned int i;
examples show how to do cli /* Save global interrupt flag */
; Read TCNT1 into r17:r16 sreg = SREG;
an atomic write of the /* Disable interrupts */
in r16,TCNT1L
TCNT1 Register contents. in r17,TCNT1H _CLI();
Writing any of the ; Restore global interrupt flag /* Read TCNT1 into i */
OCR1A/B or ICR1 out SREG,r18 i = TCNT1;
Registers can be done by ret /* Restore global interrupt flag */
SREG = sreg;
using the same principle return i;
}

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 19 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Functions of Assembly and C
The assembly code Assembly Code Example C Code Example

example requires that the TIM16_WriteTCNT1:


void TIM16_WriteTCNT1( unsigned int i )
{
r17:r16 register pair ; Save global interrupt flag unsigned char sreg;
in r18,SREG
contains the value to be ; Disable interrupts
unsigned int i;
/* Save global interrupt flag */
written to TCNT1. cli sreg = SREG;
; Set TCNT1 to r17:r16 /* Disable interrupts */
out TCNT1H,r17 _CLI();
out TCNT1L,r16 /* Set TCNT1 to i */
; Restore global interrupt flag TCNT1 = i;
out SREG,r18 /* Restore global interrupt flag */
ret SREG = sreg;
}

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 20 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Difference Between Assembly and C

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 21 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Difference Between Assembly and C

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 22 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Flowchart
The first design of flowchart goes back to 1945 which was designed by John Von Neumann. Unlike an
algorithm, Flowchart uses different symbols to design a solution to a problem. It is another commonly
used programming tool. By looking at a Flowchart, one can understand the operations and sequence of
operations performed in a system.
A flowchart is often considered a blueprint of a design used for solving a specific problem.
A flowchart is a diagrammatic representation of an algorithm. Flowcharts are very helpful in writing
programs and explaining programs to others.
Though, flowcharts are useful in efficient coding, debugging, and analysis of a program, drawing
flowcharts for very complicated in case of complex programs is often ignored.
Flowcharts use special shapes to represent different types of actions or steps in a process. Lines and
arrows show the sequence of the steps and the relationships among them. These are known as
flowchart symbols. So, flowchart symbols are specific shapes used to create a visual representation of
a program.
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 23 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Advantages of Flowchart
1. A flowchart is an excellent way of communicating the logic of a program.
2. Easy and efficient to analyze the problem using a flowchart.
3. During the program development cycle, the flowchart plays the role of a
blueprint, which makes the program development process easier.
4. After the successful development of a program, it needs continuous timely
maintenance during the course of its operation. The flowchart makes a program or
system maintenance easier.
5. It is easy to convert the flowchart into any programming language code.

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 24 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

Commonly used Operators in Flowchart


WHERE LEADERS ARE CREATED

While creating flowchart, the following mathematical operators are used.

Operator Meaning Example Remarks


+ Addition A+B Values in A and B will be added
- Subtraction A–B Values of B will be subtracted from that of A
* Multiplication A*B Values of B will be multiplied by that of A
/ Division A/B Values of A will be divided by that of B
^ Power A^3 Values of A will be raised by a power of 3
Values of A will be divided by that of A to get a
% Remainder A%B
remainder (if any)

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 25 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

Commonly used Operators in Flowchart


WHERE LEADERS ARE CREATED

While creating flowchart, the following relational operators are used.


Operator Meaning Example Remarks
< Less than A<B Value in A is less than that of B
Less than or
<= A <= B Value in A is less than or equal to that of B
equal to
= or == Equal to A = B or A == B Values of A and B are equal
# or != Not Equal to A # B, A != B Values of A and B are not equal
> Greater than A>B Value in A is greater than that of B
Greater than
>= A >= B Value in A is greater than or equal to that of B
or equal to
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 26 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

Commonly used Operators in Flowchart


WHERE LEADERS ARE CREATED

While creating flowchart, the following logical operators are used.


Operator Meaning Example Remarks
AND Logical AND A˄B Values in A and B will be ANDed
OR Logical OR A˅B Values in A and B will be ORed
NOT Logical NOT !A Values in A will be inverted

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 27 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Commonly used Symbols in Flowchart
While creating a flowchart, the following symbols
are used.
➢ Rectangle Shape - Represents a process
➢ Oval or Pill Shape - Represents the start or end
➢ Diamond Shape - Represents a decision
➢ Parallelogram - Represents input/output
➢ Circle - Represents reference/page connector
➢ Arrow - Represents a connection between shapes

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 28 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Examples of Flowchart
Draw a flowchart along with its algorithm to add two numbers entered by the user.
Start
An algorithm to find the sum of two numbers:
Declare variables
A, B, S
➢ Step 1: Start
➢ Step 2: Declare three variables
Read A, B
➢ Step 3: Read numbers and store them in the
declared variables
SA+B
➢ Step 4: Sum these two numbers and assign
Display S
them to the declared variable
➢ Step 5: Display the sum
Stop ➢ Step 6: Stop
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 29 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Examples of Flowchart
Draw a flowchart along with its algorithm to convert temperature from Celsius to Fahrenheit.
Start

➢ Step 1: Start
➢ Step 2: Declare two variables
Declare variables
C, F

➢ Step 3: Read the temperature value in Celsius scale and


Read C
store it in one of the declared variables
➢ Step 4: Apply the formula of temperature conversion i.e.,
F  (9*C)/5 + 32
F = (9*C)/5 + 32 to the convert Celsius value in
Display F
Fahrenheit scale and store it in the declared variable
➢ Step 5: Display the temperature in Fahrenheit scale
Stop ➢ Step 6: Stop
Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan
Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 30 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED


Examples of Flowchart
Draw a flowchart along with its algorithm to print numbers from 1 to 20.

➢ Step 1: Start
➢ Step 2: Declare and initialize a variable with a 0 value
➢ Step 3: Increment the variable value by 1 and store it
in the same declared variable
➢ Step 4: Print the value stored in the variable
➢ Step 5: If the variable is < 20 then go to step 3,
otherwise go to the next step
➢ Step 6: Stop

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 31 of Total 32 Slides
Lecture # 05: Assembly Language Programming for ATmega328P

WHERE LEADERS ARE CREATED

Thanks for attending….

Course Teacher: Prof. Dr. Engr. Muhibul Haque Bhuyan


Professor, Department of EEE, American International University-Bangladesh (AIUB), Dhaka, Bangladesh Slide # 32 of Total 32 Slides

You might also like