Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!alonzo From: alonzo@microsoft.UUCP (Alonzo GARIEPY) Newsgroups: comp.sys.handhelds Subject: Re: Machine code on the 28S (and 48SX) Message-ID: <55066@microsoft.UUCP> Date: 6 Jun 90 04:14:56 GMT References: <55022@microsoft.UUCP> <1990Jun4.222439.21761@portia.Stanford.EDU> Reply-To: alonzo@microsoft.UUCP (Alonzo GARIEPY) Organization: Microsoft Corp., Redmond WA Lines: 111 In <1990Jun4.222439.21761@portia.Stanford.EDU> (Andrew Zimmerman) writes: > A couple of questions of the hp48sx assembly language. My sources for these > questions are notes by Alonzo Gariepy for the hp-28s and the recent note > about the 48sx. Question #1 ----------- > DB 02 ; number of characters in string > DB "RR" ; the string > D3 003 ; XLIB# ? > So, where do the extra 3 nybbles come from in the document? The entry in my HP-48 XLIB listing is: 195DB 003002 RR These are: the RPL (SYSEVAL) address of the command, the XLIB#, and the command name. Commands and functions can be stored in two forms within a program: as the RPL address or as an XLIB object. The program editor knows how to look up the address form to find the name of the command or function. When it finds an address it doesn't recognize it displays An XLIB object comprises the prolog (02E92), the library number (002 for commands and functions, 700 for control structures), and the index (the RR command's index is 003, RAND's is 07F). That is 11 nibbles total. Commands and functions are treated as different types at the user level (types 18 and 19, respectively); any other XLIB is displayed as XLIB xxx xxx which is called an XLIB Name (type 14). The reason the library number doesn't appear in the table is that there is a separate table for each library. But the library number does appear in every XLIB object. Question #2 ----------- > What is register D1 used for? The documents say that Register D1 points > to the end of the stack growing down toward the heap. I interpret this to > mean that D1 is the stack pointer. But, in disassembling the code for > peek, we have a sequence of instructions that have > > MOVE.A @D1,A ; Get pointer to first object off stack > MOVE.A A,D0 ; and put it in D0 > ADD.a 10,D0 ; point to 10th nib (after prolog and length) > MOVE.A @D0,C ; move first 5 nibbles of object data into C > SWAP.A C,D0 ; put object data into D0 (swap is irrelevant) > MOVE.W @D0,C ; use data as address of 16 nibs to put in C The comments above are mine, and explain what is going on. Each element of the stack is a 5 nibble address that points to an object. If you type "Hello" DUP the stack consists of two identical pointers to the same "Hello" string. The D1 register points to the top of the stack, which is an address. In the code above, at the top of the stack is the address of a binary integer which hold the PEEK address. MOVE D1,A would just move the address of the top of stack into register A. MOVE @D1,A moves the address of the binary object into A. We then increment 10 so that A points to the PEEK address just after the prolog and length (5 nibbles each) of the binary integer. Question #3 ----------- > If I look at the code for ASR at 1957B, I see D9D2.. which appears to be > D9 MOVE.A B,C > D2 CLR.A C > Is this correct? Seems it is clearing reg C after putting something in it. Commands, Functions, SYSEVALs, etc. point to RPL objects, not machine code. What you are really seeing is the prolog (02D9D) of a RPL program object. Every RPL routine begins with these five nibbles. A machine code object begins with 02DCC and a five nibble length. Note that all addresses appear in reverse order in memory. Question #4 ----------- > Does anyone know where the processor starts execution? I am guessing that > it starts at 00000. (Sorry all you motorola people out there :-)) The processor begins at the beginning, 00000. The instructions there are: #00000: #23 MOVE.1 3,P #00002: #69B1 JUMP.3 #001BC ... #001BC: #8D6CF10 JUMP.A #01FC6 ... #01FC6: #846 CLRB 6,ST #01FC9: #842 CLRB 2,ST #01FCC: #857 SETB 7,ST #01FCF: #6310 JUMP.3 #01FE3 I assume that the setting of the status register is used to configure the operation of the initialization routines. Have fun at #01FE3 Question #5 ----------- > How was the instruction set determined? Boy, I can't find any fields > in it, and those it appears to have move around. I agree. Sometimes availability, not suitability, is the deciding factor. It can be shown that the Saturn instruction set is not very well suited to its work, but now there is an enormous body of excellent code that it would be impractical to replace. I once designed a macro language, which I named QUAD for QUick And Dirty so I wouldn't feel defensive if it was every foisted on someone outside my project. We can only imagine how the designers of the Saturn feel :-). Thanks for providing so much information with your questions. It is too time consuming for me if I have to research and invent examples. Alonzo Gariepy // The content of this message does not alonzo@microsoft // represent the policies of Microsoft Corp.