
Naviagtion
Home
|
8048 Cross Overlay Overview
IntroductionTalking about old, the 8048 family can be considered the dinosaurs under the microcontrollers. They are not extinct yet, some devices are still running on them, but for how long from now? In fact at the time I wrote this text for the SB-Assembler version 2 the brains of my living room TV set was still a 8048 based microcontroller!
The 8048 was the predecessor of the still very popular 8051 microcontrollers.
Many of the 8051's features are inherited from the 8048 family, like the programming model and the timer functions.
Many different derivatives exist, marketed by different manufacturers.
The different derivatives differ mostly in I/O capabilities.
Due to the architecture these I/O features all require new instructions or different operands.
Therefore every derivative needs its own cross assembler.
Programming ModelThe programming model in the picture below shows the most important registers of the 8048 processor. I only include a little summary about the features of the 8048's programming model here. It is not my intention to make the original documentation obsolete, so please refer to the original documentation for further details.
The Accumulator The Accumulator is the most important register for 8 bit arithmetic operations. Its standard name is A, which is a reserved word. The Program Status Word The PSW contains 8 system flags:
Bits 2..0 are the stack pointer of the 8048, limiting the stack to a maximum depth of 8 levels.
This means that up to 8 subroutine calls (or 7 and one interrupt) can be nested before the stack overflows.
No particular action is taken when the stack does overflow, you simply loose your oldest return address, which will very likely crash your program.
The stack is part of internal RAM and occupies addresses $08 to $17, which is in between the two register banks mapping.
A call instruction (or an interrupt) will cause the low byte of the program counter to be stored first in the lowest address, followed by a concatenation of the 4 upper bits of the PSW and bits b11..b8 of the program counter which is saved at the next address.
After that the stack pointer is incremented by one.
Although the stack pointer is incremented by 1 the actual increment is 2 because every call involves the pushing of 2 bytes on the stack.
The Register R0 ... R7
8 registers assist the 8048 as intermediate registers during calculations.
The registers are part of internal RAM memory.
Registers R0 and R1 can also be used as pointers during indirect addressing. The Program Counter The program counter PC is only 11 bits long, enabling it to address 2k of memory. A 12th bit is added to the program counter and effectively is a bank switch bit. If the 11 bit program counter overflows it will wrap around and doesn't increment b11 automatically. The only way to change b11 is by executing the SEL MB0 or SEL MB1 instruction, followed by a JMP or CALL instruction. The actual switching to the new bank is delayed until the program actually JMPs or CALLs to the new location. Interrupts can only use bank 0 of the program memory.
The SB-Assembler won't allow you to use memory locations above 2k.
If you want to use memory in bank 1 you'll have to restart your program counter at $000 again.
The easiest way to do that is to use the directives .NO $800 and .PH $000 together at the end of bank 0.
That way the object file will continue to grow with unique addresses, while the assembler uses the right addressing range for the 8048.
TimingSB-Assmebler Version 3 can show you the cycle times of each instruction when the TON list flag is switched on. The numbers presented are the number of cycles each instruction takes. Reserved Words
The SB-Assembler 8048 cross overlay has a few reserved words.
Reserved words are all fixed register names.
You better avoid these reserved words when you assign your own labels.
E.g. don't name your labels R0, or A.
Here's the list of all reserved words: A, R0, R1, R2, R3, R4, R5, R6, R7 If you take a look at the 8048 instruction set you may expect more reserved words to exist, like MB0 or TCNTI. But because the instructions that use these operands never expect expressions as their operands no unpredictable behaviour of the assembler is to be expected if you do name your labels equally. Special FeaturesMemory Page boundary detection
The program memory space of the 8048 is (invisibly) divided in pages of 256 bytes each.
Branch instructions cannot cross these boundaries and destinations are restricted to the same page as the branch instruction itself.
There is also another problem caused by this page boundary system.
ROM lookup tables are also restricted to pages.
The instructions reading the table must reside in the same page as the table and the table itself may not cross a page boundary.
The only exception to this rule is when you place your table on memory page 3, because a special instruction (MOVP3 A,@A) exists that can read a table from page 3 from anywhere in program memory.
Bank switching
Standard features of the SB-Assembler aid in the concept of bank switching in 8048 programming.
Remember that the 8048 can only address 2k of ROM memory.
It has a bank switch bit (b11 of PC) to expand its ROM capacity to 4k.
The trick is to start page 1 with address $000 again, but that could cause some unexpected problems.
Suppose you want the whole object code written to the same formatted target file like e.g. a file with the Intel hex format.
Now your programming device probably gets quite confused when it finds 2 memory blocks both starting from address $000 and both having different data.
Let me explain what happens.
The .OR or the .NO directive will set the program counter to $800, which is actually one more than the 8048 can handle.
But the SB-Assembler will not protest as long as you don't write anything to that address.
Now the .PH directive lets the SB-Assembler think it is assembling a program from address $000.
In reality the generated object code is written to your target file from address $800 and up, while labels, jumps and calls are properly calculated having addresses in the range from $000 to $7FF.
As of version 3 of the SB-Assembler there's another way of handling the bank switching. This way is a bit more straight forward, and therefore possibly easier to comprehend.
Please note that this approach is just the opposite of the previous one.
Instead of setting the new program counter to $800, it is now set to $000.
The correct target address in the target file is then enforced by the .TA directive.
Error MessagesOne new error message is added to the SB-Assembler while the 8048 cross overlay is loaded: Table crossed page boundary error
This error is generated by the .CT directive and sometimes by the .OT.
Overlay InitializationThree things are set while initializing the 8048 related overlays every time one is loaded by the .CR directive.
.CT Close TableSyntax: .CT Function: This directive signals the end of your table in memory. It will present a "Table crossed page boundary error" if this directive is located on a different page than was stored by the previous .OT directive. Explanation: Tables are not allowed to cross page boundaries. That's why the .OT and .CT directives are used to signal the beginning and the end of a table, verifying that a page crossing hasn't occurred in between. The .OT directive should be placed at the beginning of the table. More precisely just before the instruction that reads the table, because that instruction should be on the same page too. The only exception to this rule would be the MOVP3 A,@A instruction that may be anywhere in the same memory bank as the table which should be stored in page 3.
The .OT directive will memorize the memory page of the beginning of the table.
At the end of the table the closing .CT directive should still be in the same memory page.
There's only one exception to this rule and that is when .CT is at the first location of the next page, because then the table ended just in time on the previous page.
Example The example below shows a typical lookup table routine. It converts a decimal digit to a seven segment pattern. I think it clearly demonstrates the use of the .OT and .CT directives.
DEC2SEGM MOV A,R0 Get decimal value
ADD A,#SEGMENTS Add offset to table to it
.OT Mark the beginning
MOVP A,@A Get 7 segment pattern
RET
SEGMENTS .DA #%0011.1111 0
.DA #%0000.0110 1
.DA #%0101.1011 2
.DA #%0100.1111 3
.DA #%0110.0110 4
.DA #%0110.1101 5
.DA #%0111.1101 6
.DA #%0000.0111 7
.DA #%0111.1111 8
.DA #%0110.1111 9
.CT End of table, checking page
Please note that the .OT directive is placed before the MOVP instruction because that instruction must be on the same page as the rest of the table. The .CT directive is ignored if no matching .OT directive was used. .OT Open TableSyntax: .OT Function: This directive signals the beginning of your table in memory. Explanation: .OT saves the current memory page address internally. Later on it should match the memory page address of the next .CT directive.
The .OT directive will automatically call the .CT function if you previously started a table without closing it properly with a .CT directive.
After closing the previous table this way the new table will start at the current location as if you had inserted a .CT directive yourself.
This way you can concatenate several tables after each other.
Please note that the .OT directive would never generate the "Table crossed page boundary error" itself if it wasn't for the automatic calling of the .CT routine when a previous table wasn't closed. Differences With Other AssemblersThere are no specific differences between the SB-Assembler and other assemblers for the 8048 processor family other than the obvious differences which all SB-Assembler crosses have in common. These differences require you to adapt existing source files before they can be assembled by the SB-Assembler. This is not too difficult though and is the (small) price you have to pay for having a very universal cross assembler.
|
|||||||||||||||||||||||||||||||||||||||||