0% found this document useful (0 votes)
8 views17 pages

Micro Session5

The document provides an overview of microcontroller operations, including byte-oriented and bit-oriented operations, as well as instructions for decimal adjustment, program memory access, and subroutines versus macros. It explains specific instructions like BSF, DAW, TBLRD, and their functions in manipulating data. Additionally, it discusses the advantages and disadvantages of using subroutines and macros in programming, highlighting their respective use cases.

Uploaded by

georgesatieh4
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)
8 views17 pages

Micro Session5

The document provides an overview of microcontroller operations, including byte-oriented and bit-oriented operations, as well as instructions for decimal adjustment, program memory access, and subroutines versus macros. It explains specific instructions like BSF, DAW, TBLRD, and their functions in manipulating data. Additionally, it discusses the advantages and disadvantages of using subroutines and macros in programming, highlighting their respective use cases.

Uploaded by

georgesatieh4
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/ 17

Microcontrollers

Clara Zaiter
[email protected]

ULFG2 Sem 7 - 2024


Outline
• Byte-oriented operations on f
• Bit-oriented operations on f
• Daw instruction
• call, rcall and return instructions
• Program memory Rd/Wr instructions
• Subroutines vs Macros
Byte-Oriented Operations on f
Bit-Oriented Operations on f
Bit Set Instruction
bbb:
000 → 00000001 BIT 0
001 → 00000010 BIT 1
010 → 00000100 BIT 2
011 → 00001000 BIT 3
100 → 00010000 BIT 4
101 → 00100000 BIT 5
110 → 01000000 BIT 6
111 → 10000000 BIT 7
Bit Set Instruction
Assuming register 0x20 holds the value ‘0100 0010 (binary)

BSF 0x20, 3
Bit 3 in register 0x20 will be set
Daw Instruction
This instruction (decimal adjust WREG) adjusts the 8-bit value in WREG resulting from the earlier addition
of 2 numbers (each in packed BCD format).
▪ BCD (binary coded decimal) numbers represent the decimal digits 0 through 9 with a 4-bit binary equivalent.
▪ Packed BCD numbers concatenate 2 BCD digits in one 8-bit register.

The carry bit is affected by the daw instruction and is used as a carry in for 16-bit packed BCD additions.

For instance, the addition of 0x08 to 0x04 results in 0x0C which is the correct value in binary form.
The decimal adjust instruction converts this result to 0x12. This is done as follows:
Call/recall and return Instructions
Call/recall and return Instructions
Call/recall and return Instructions
The retlw instruction operates like the return instruction.
Besides this, it sends back a constant value via the working register. It is similar to the C
return statement in the following function.
Program memory Rd/Wr Instructions
There are essentially two instructions dealing with program memory: tblrd and tblwt along
with their variants. The registers involved in reading from or writing to PM are TBLPTR and
Table Latch (or TABLAT) .
tblrd Instruction
This allows reading of data bytes stored side by side in program space by:
1. Loading the 21-bit register TBLPTRU:TBLPTRH:TBLPTRL with the address of the memory
location to be read.
The db (define byte) directive is used to store a set of consecutive table entries in PS as in:

In order to let TBLPTR point to address Table declared at address 0x1234 in PS, the following
sequence of instructions will do the job.
tblrd Instruction
2. Executing instruction tblrd which moves the contents of the location pointed to by TBLPTR
into TABLAT.

Assuming TBLPTR holds the address Table + 2


initially.

After execution:

TABLAT =
TBLPTR =
WREG =
tblrd Instruction

Note that the tblrd instruction does not affect the STATUS bits. Therefore, in order to check whether a
table entry is zero, use the following code:
Subroutines
• A subroutine is a separate block of code that can be called from multiple places in
a program. The control jumps to the subroutine, executes the code, and then
returns to the caller.

• It is memory-efficient because the code exists only once in memory. Each call to
the subroutine reuses this code.

• Has some overhead due to jumping to the subroutine and returning, which can
take additional clock cycles.

• Easier to debug and maintain. Changes made to a subroutine affect all calls to it,
and breakpoints can be set to test and step through the code.
Macros
• A macro is a preprocessor directive that allows you to define a block of code with
a name. When the macro is called, the assembler expands it inline by replacing
the macro name with its code, essentially copying the code wherever it’s called.

• Less memory-efficient, especially if used frequently, because each macro


invocation generates a full copy of the macro code, increasing the code size.

• Executes faster as it is expanded inline with no jumps or returns, making it


suitable for time-critical operations where speed is crucial.

• Harder to debug because each instance of the macro is expanded inline, making it
challenging to identify where a particular instance may have caused an error.
Subroutines vs Macros
• Use subroutines for larger, reusable code blocks, especially where memory
efficiency matters.

• Use macros for smaller, frequently repeated tasks where execution speed is
paramount.

You might also like