In SX Microcontrollers, SX/B Compiler and SX-Key Tool, g_daubach wrote: Samuel, please don't think I'm picky - I just want to make sure that others who read this thread are not mis-led. The RETP instruction does _NOT_ restore the STATUS register - just the upper three PA bits in this register. All other bits, like Z, C, DC, etc. remain unchanged. As I had mentioned in my last post, there is an internal program counter in the SXes (11 bit wide in devices up to the SX28, 12 bit wide in the SX 48/52 devices). This program counter is used to internally address program memory. The PC register that is mapped into the variable address space at address 2, and that can be accessed by program instructions is only 8 bits wide, and it represents the lower eight bits of the internal program counter. So SXSim exactly shows the eight bits that can be accessed (as does the SX-Key debugger). The SX addressing scheme seems to be a bit weired on the first glance. To understand it, you always must keep in mind that each instruction the SX "knows" is always one word (12 bits) wide. Each instruction is composed of some higher bits that specify the instruction per-se, followed by some lower parameter bits that specify a value, like a constant or an address. For example, the instruction code for JMP is composed like this: 101a aaaa aaaa i.e. the leading "101" "tells" the SX to perform a jump, and the following 9 bits contain the target address. Obviously, 9 bits can only address 512 memory locations. To address all program memory, 11 bits (or 12 for the SX 48/52) are required. Therefore, to compose a complete jump address, two (or three) of the page bits in the STATUS register are used. The resulting full address is then copied into the internal progral counter to actually perform the jump. Similar to JMP, the code for CALL is: 1001 aaaa aaaa Here, the instruction part is 4 bits wide, only leaving 8 bits for the call address. To compose a full call address, the 9th bit is always set to 0 here, and the upper two or three bits are read from the upper STATUS register bits, as before. This is the reason why entry points of subroutines can only be located within the first half of each code page as there is no room in the instruction code for the 9th bit, so it is always cleared. BTW - if you have my book on hand, you'll find a more detailled explanation at page 157 ff. You can also find similar information in the SX datasheets. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=104866#m104936 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)