Path: utzoo!utgpu!watserv1!watmath!att!pacbell!pacbell.com!ames!elroy.jpl.nasa.gov!usc!cs.utexas.edu!uunet!microsoft!alonzo From: alonzo@microsoft.UUCP (Alonzo GARIEPY) Newsgroups: comp.sys.handhelds Subject: Machine code on the 28S (and 48SX) Message-ID: <55022@microsoft.UUCP> Date: 3 Jun 90 22:43:42 GMT Reply-To: alonzo@microsoft.UUCP (Alonzo GARIEPY) Organization: Microsoft Corp., Redmond WA Lines: 126 In email, writes | Hello Alonzo: | | There are still many details about which I am confused. Can you tell me | how to determine where to peek to view the code which is called by the | routine below? Even after studying your processor notes I'm unable to | understand the instruction: 8Exxxx CALL.4 PC+6+xxxx. | | #44A4h: #9A440 | #8E87A0 ???? | #147 move.a @d1,c | #137 swap.a c,d1 | #141 move.a a,@d1 | #135 move.a c,d1 | #142 move.a @d0,a | #164 add.a 5,d0 | #808C jump @a | | What did you mean when you said relative CALLS contain an offset from | the next instruction? | | And also, what did you mean when you said that these are expressed relative | to the address of the call instruction itself (PC). | | Would you explain what it means when you stated that offsets are | in 2's complement form? | | Lastly, how does the program counter enter in to: PC+6+xxxx? | | Thanks for any help you can give! | | Rick First, I have translated the listing to canonical form. The answer to your primary question is evident from the listing: the called routine is at #04f27. #044A4: #9A440 #044a9: #8E87A0 call.4 #04f27 #044af: #00147 move.a @d1,c #044b2: #00137 swap.a c,d1 #044b5: #00141 move.a a,@d1 #044b8: #00135 move.a c,d1 #044bb: #00142 move.a @d0,a #044be: #00164 add.a #5,d0 #044c1: #00808C jump @a Now your other questions: | What did you mean when you said relative CALLS contain an offset from | the next instruction? The jump instruction is described in the notes as 6xxx JUMP.3 PC+1+xxx Take an example such as #00086: #6634 jump.3 #004bd In this case the PC is #00086, xxx is #436 (remember to reverse it) so the destination is #86+1+#436 = #004bd. The offset is relative to the second nibble of the current instruction (i.e., PC + 1). The call.4 instruction is described in the notes as 8Exxxx CALL.4 PC+6+xxxx Take an example such as #03acd: #8eea51 call.4 #05081 In this case the PC is #03acd, xxxx is #15ae (remember to reverse it) so the destination is #03acd+6+#15ae = #05081. The offset is relative to the first nibble of the next instruction (for call.4 that means PC + 6). In the Saturn CPU, all call offsets are relative to the first nibble of the next instruction. | And also, what did you mean when you said that these are expressed relative | to the address of the call instruction itself (PC). For uniformity, I have written all address equations in terms of the current PC. Because the Saturn uses different base addresses to offset for jumps and calls, I have specify correction factors such as +1, +2, and +6. You can see how these work from the above examples. | Would you explain what it means when you stated that offsets are | in 2's complement form? That means that if the high bit is a 1, the offset is actually negative. But there are at least three ways to write a negative number in binary. The Saturn uses 2's complement form because the final address can be calculated simply by sign extending the offset and adding it. Sign extension means taking the highest bit (1 or 0) and copying it all the way to the left. Take an example such as #00405: #6edf jump.3 #003e4 Note that xxx is #fde. In binary, that is 1111 1101 1110. We can calculate the final address (PC+1+xxx) by sign extending xxx and adding it to PC+1 PC 0000 0000 0100 0000 0101 + 1 0000 0000 0000 0000 0001 + xxx 1111 1111 1111 1101 1110 = ======================== PC+1+xxx 0000 0000 0011 1110 0100 (extra carry is discarded) Note that both postive and negative numbers are said to be in 2's complement form in this system and both are sign extended before the addition, but the sign bit for postive numbers is 0 and it has no real effect. For simpler, manual subtraction, a 2's complement number can be negated by sign extending, inverting all its bits and adding 1. (1) #fde (2) #fffde (sign extend) (3) #00021 (invert) (4) #00022 (add 1) So the offset is really #-22. The destination, expressed relative to the PC is PC+1-#22 or PC-#21 #00405: #6edf jump.3 PC-#21 (#003e4) | Lastly, how does the program counter enter in to: PC+6+xxxx? I use PC to mean the address of the current instruction. That is not the way some processor manuals do it, but I find it simpler. It is a pleasure to respond to such clearly stated questions. alonzo