\chapter{Understanding the Output} \section{Introduction} {\rm oggin} is designed for examining the operation of instructions step by step through its one-line outputs. Besides changes to registers and memory, the {\rm oggin} CAL tool also displays an explanation and comment for each instruction. Additionally, locations are highlighted when significant changes occur or special attention is required. The user would be hopefully more impressed. The output in some conditions has a lot of details which is deliberately designed to make the tool more helpful and easy to understand. For the purpose of making the best out of the design, it is rewarding to have an overview of the results through some regular and special output examples. \\ \\ Difference between each display of output is effected by the function code of each instruction. However, some information of the output is the same if the function codes are the same group. So it would be appropriate to introduce the output according to the function code groups. \section{Output of Group 1} The results of instructions which have function code of group 1 in some way are similar, while in some other way it varies obviously from different function codes. \\ \\ All function codes in group 1 need to access memory except when the addressing mode is immediate. The memory location accessed is highlighted. Fig 5.1 shows the output of the current instruction, {\it lda,\#,177}, in the middle of the three instructions and highlighted. \\ \\ The binary code for {\it lda,\#,177} is 0001000001111111, displayed above it; the octal code {\it 010177} for it is just at its right side; the function code is {\it lda} which belongs to group 1. The addressing mode is immediate; the operand is 177 and no memory is accessed because it is immediate addressing mode. \\ \\ Below this basic explanation is a comment for the instruction saying :{\it load value of 177 to accumulator}. Checking the value of acc at the top of the screen shows acc highlighted and its contents is 000177. Now if a key is pressed, the screen will be redrawn and the output will be as in Fig 5.2. This time the instruction is {\it lda,d,100}, which was the next instruction shown below the previous one {\it lda,\#,177}; this is now present above the current one. Below the current instruction is a new `next instruction'. It could prove part of the {\bf process} concept that {\it different instructions, in turn, become `the next instruction' to be executed.} \\ \\ The binary code has already changed, and the octal code as well. It is direct addressing mode, so the ACCESS LOCATION is 100. The comment for the current instruction says : {\it load data of location 100 to acc }. Looking at acc and location 100 shows that they are both highlighted and have the same value. The previous acc value 000177 is now lost. \\ \\ The results of the other function codes of group 1 is basically the same except for the highlighted position and the comments. If the function code is {\it ldi}, for instance, it will highlight the index register instead of acc, as in Fig 5.3. \\ \\ There are only two assembly language instructions shown on Fig 5.3 because {\it ldi,\#,100} is the first instruction (at location zero). \newpage \vspace*{60mm} \dspaceoff \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000001 010177 000177 002000 000100 0000 000002 INSTRUCTIONS : 0001000001111111 EXPLANATION : ldi,#,100 lda,#,177 OCTAL CODE : 010177 lda,d,100 FUNCTION CODE : lda OPCODE GROUP : group 1 ADDRESSING MODE : immediate MAIN MEMORY OPERAND : 177 ACCESS LOCATION : none 0 030100 010177 012100 014101 4 016000 016002 016127 030100 load 177 to acc. 10 010000 120070 122103 124104 14 126003 010101 000005 040001 20 000005 042105 122103 000006 24 000006 000000 000000 000000 30 000000 000000 000000 000000 34 000000 000000 000000 000000 Press q for exit and any other 40 000000 000000 000000 000000 keys for next instruction: 44 000000 000000 000000 000000 Fig 5.1 The lda instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000002 012100 125252 002000 000100 0100 000003 INSTRUCTIONS : 0001010001000000 EXPLANATION : lda,#,177 lda,d,100 OCTAL CODE : 012100 lda,i,101 FUNCTION CODE : lda OPCODE GROUP : group 1 ADDRESSING MODE : direct MAIN MEMORY OPERAND : 100 ACCESS LOCATION : 100 64 000000 000000 000000 000000 70 040002 000001 000000 000000 load data of location 100 74 000000 000000 000000 000000 to acc. 100 125252 000105 052525 000070 104 000103 000010 000000 000000 110 000000 000000 000000 000000 114 000000 000000 000000 000000 120 000000 000000 000000 000000 Press q for exit and any other 124 000000 000000 000000 000000 key for next instruction: 130 000000 000000 000000 000000 Fig 5.2 The lda instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000000 030100 000000 002000 000100 0000 000001 INSTRUCTIONS : 0011000001000000 EXPLANATION : ldi,#,100 OCTAL CODE : 030100 lda,#,177 FUNCTION CODE : ldi OPCODE GROUP : group 1 ADDRESSING MODE : immediate MAIN MEMORY OPERAND : 100 ACCESS LOCATION : none 0 030100 010177 012100 014101 4 016000 016002 016127 030100 load 100 to index register. 10 010000 120070 122103 124104 14 126003 010101 000005 040001 20 000005 042105 122103 000006 24 000006 000000 000000 000000 30 000000 000000 000000 000000 34 000000 000000 000000 000000 Press q for exit and any other 40 000000 000000 000000 000000 keys for next instruction: 44 000000 000000 000000 000000 Fig 5.3 The ldi instruction \end{verbatim} \newpage \dspaceon \noindent If the function code is either {\it jsr} or {\it jmp}, the pc is highlighted to draw the user's attention to any unusual changes to pc. Fig 5.4 shows the result of instruction {\it jsr,d,103}. The new pc is pointing to 70 rather than 13, following the current instruction at location 12. \\ \\ Comments are different for each instruction. Those for function codes, such as {\it add}, {\it sub}, {\it and},{\it ora}, {\it cmp}, however, are similar. The display shows the binary values of the previous acc, the source and the result of operation, as in Fig 5.5, where the function code is {\it and},\\ \hspace*{10mm}the OLDacc is 1111111001110101,\\ \hspace*{10mm}the SOURCE is 0000111111000111 and \\ \hspace*{10mm}the RESULT is 0000111001000101. \\ \\ The octal code of the RESULT is 007105 which is equal to the contents of acc. The result of operation is usually returned to acc except when the function code is `cmp'. Fig 5.6 is the result of `cmp', showing the contents of acc unchanged. \newpage \vspace*{60mm} \dspaceoff \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000012 122103 000002 001777 000100 0000 000070 INSTRUCTIONS : 1010010001000011 EXPLANATION : rts jsr,d,103 OCTAL CODE : 122103 add,#,2 FUNCTION CODE : jsr OPCODE GROUP : group 1 ADDRESSING MODE : direct MAIN MEMORY OPERAND : 103 ACCESS LOCATION : 103 64 000000 000000 000000 000000 70 040002 000001 000000 000000 jump to subroutine in 70. 74 000000 000000 000000 000000 100 125252 000105 052525 000070 104 000103 000010 000000 000000 110 000000 000000 000000 000000 114 000000 000000 000000 000000 120 000000 000000 000000 000000 Press q for exit and any other 124 000000 000000 000000 000000 key for next instruction: 130 000000 000000 000000 000000 Fig 5.4 The jsr instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNVZ= pc<- 000006 072063 007105 002000 000000 1000 000007 INSTRUCTIONS : 0111010000110011 EXPLANATION : sub,d,62 and,d,63 OCTAL CODE : 072063 sta,d,64 FUNCTION CODE : and OPCODE GROUP : group 1 ADDRESSING MODE : direct MAIN MEMORY OPERAND : 63 ACCESS LOCATION : 63 44 000000 000000 000000 000000 50 000000 000000 000000 000000 54 000000 000000 000000 000000 acc <- acc AND src 60 037402 030111 010204 007707 OLDacc : 1111111001110101 64 000000 170016 000100 000000 SOURCE : 0000111111000111 70 000000 000000 000000 000000 RESULT : 0000111001000101 74 000000 000000 000000 000000 100 000000 000000 000000 000000 Press q for exit and any other 104 000000 000000 000000 000000 key for next instruction: 110 000000 000000 000000 000000 Fig 5.5 The and instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000070 060012 000037 001774 001774 0000 000071 INSTRUCTIONS : 0110000000001010 EXPLANATION : bcs,70 cmp,#,12 OCTAL CODE : 060012 bge,106 FUNCTION CODE : cmp OPCODE GROUP : group 1 ADDRESSING MODE : immediate MAIN MEMORY OPERAND : 12 ACCESS LOCATION : none 1730 000000 000000 000000 000000 1734 000000 000000 000000 000000 1740 000000 000000 000000 000000 result = acc - src 1744 000000 000000 000000 000000 OLDacc : 0000000000011111 1750 000000 000000 000000 000000 SOURCE : 0000000000001010 1754 000000 000000 000000 000000 RESULT : 0000000000010101 1760 000000 000000 000000 000000 1764 000000 000000 000000 000000 Press q for exit and any other 1770 000000 000000 000000 000000 keys for next instruction: 1774 000000 000000 000020 000060 Fig 5.6 The cmp instruction \end{verbatim} \newpage \dspaceon \section{Output of Group 2} The basic explanation part for function codes of group 2, including the extended instruction set, is similar; but their comments and highlighted positions are significantly different. \\ \\ If function codes are {\it trp} and {\it rtt}, the psw, new pc and the two memory locations accessed are highlighted. Their relations can be learned from the comments. Fig 5.7 is result of {\it trp} and Fig 5.8 is for {\it rtt}. The user will realise the top part of memory is assumed to be the stack, and it is accessed in a downward direction. \\ \\ If function codes are {\it lsr}, {\it lsl}, {\it asr}, {\it asl}, the psw is highlighted for checking the status of the C-bit when the user has visualised the binary values of acc before and after shift. Fig 5.9 shows the result of {\it asr}, with comments in detail. \\ \\ In the case of {\it rts}, the new pc and the accessed location of the stack is highlighted. From the comment of Fig 5.10 for {\it rts}, it says {\it return from subroutine to location 12}, the user should know that the return address is pulled from the stack. \newpage \dspaceoff \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000103 000011 177420 001776 000000 0000 000020 INSTRUCTIONS : 0000000000001001 EXPLANATION : lsr trp OCTAL CODE : 000011 lda,d,70 FUNCTION CODE : trp OPCODE GROUP : group 2 ADDRESSING MODE : none MAIN MEMORY OPERAND : none ACCESS LOCATION : 1777 & 1776 1730 000000 000000 000000 000000 1734 000000 000000 000000 000000 perform a synchronous trap 1740 000000 000000 000000 000000 push current psw to 1777 1744 000000 000000 000000 000000 push current address to 1776 1750 000000 000000 000000 000000 obtain new ps and psw from 1754 000000 000000 000000 000000 location 10 and 11 1760 000000 000000 000000 000000 1764 000000 000000 000000 000000 Press q for exit and any other 1770 000000 000000 000000 000000 keys for next instruction: 1774 000000 000000 000104 000005 Fig 5.7 The trp instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000023 000012 000000 001777 000000 0101 000104 INSTRUCTIONS : 0000000000001010 EXPLANATION : clr rtt OCTAL CODE : 000012 blt,120 FUNCTION CODE : rtt OPCODE GROUP : group 2 ADDRESSING MODE : none MAIN MEMORY OPERAND : none ACCESS LOCATION : 1776 & 1777 1730 000000 000000 000000 000000 1734 000000 000000 000000 000000 return from trap 1740 000000 000000 000000 000000 pop return address from 1744 000000 000000 000000 000000 location 1776 to pc 1750 000000 000000 000000 000000 pop psw from location 1754 000000 000000 000000 000000 1777 to psw 1760 000000 000000 000000 000000 1764 000000 000000 000000 000000 Press q for exit and any other 1770 000000 000000 000000 000000 keys for next instruction: 1774 000000 000000 000104 000005 Fig 5.8 The rtt instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000013 000002 003442 002000 007105 1001 000014 INSTRUCTIONS : 0000000000000010 EXPLANATION : ldi,i,66 asr OCTAL CODE : 000002 lsr FUNCTION CODE : asr OPCODE GROUP : group 2 ADDRESSING MODE : none MAIN MEMORY OPERAND : none ACCESS LOCATION : none 64 007105 170016 000100 000000 70 000000 000000 000000 000000 acc shifted right 1 place. 74 000000 000000 000000 000000 Bit 15 is replicated, and 100 007105 000000 000000 000000 bit 0 shifted to C bit. 104 000000 000000 000000 000000 OLDacc : 0000111001000101 110 000000 000000 000000 000000 NEWacc : 0000011100100010 114 000000 000000 000000 000000 120 000000 000000 000000 000000 Press q for exit and any other 124 000000 000000 000000 000000 key for next instruction: 130 000000 000000 000000 000000 Fig 5.9 The asr instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000071 000001 000002 002000 000100 0000 000012 INSTRUCTIONS : 0000000000000001 EXPLANATION : add,#,2 rts OCTAL CODE : 000001 jsr,d,103 FUNCTION CODE : rts OPCODE GROUP : group 2 ADDRESSING MODE : none MAIN MEMORY OPERAND : none ACCESS LOCATION : 1777 1730 000000 000000 000000 000000 1734 000000 000000 000000 000000 return from subroutine to 1740 000000 000000 000000 000000 location 12 1744 000000 000000 000000 000000 1750 000000 000000 000000 000000 1754 000000 000000 000000 000000 1760 000000 000000 000000 000000 1764 000000 000000 000000 000000 Press q for exit and any other 1770 000000 000000 000000 000000 keys for next instruction: 1774 000000 000000 000000 000012 Fig 5.10 The rts instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000016 000005 000101 001777 000100 0000 000017 INSTRUCTIONS : 0000000000000101 EXPLANATION : lda,#,101 psh OCTAL CODE : 000005 add,#,1 FUNCTION CODE : psh OPCODE GROUP : group 2 ADDRESSING MODE : none MAIN MEMORY OPERAND : none ACCESS LOCATION : 1777 1730 000000 000000 000000 000000 1734 000000 000000 000000 000000 push value of acc to stack 1777 1740 000000 000000 000000 000000 1744 000000 000000 000000 000000 1750 000000 000000 000000 000000 1754 000000 000000 000000 000000 1760 000000 000000 000000 000000 1764 000000 000000 000000 000000 Press q for exit and any other 1770 000000 000000 000000 000000 keys for next instruction: 1774 000000 000000 000000 000101 Fig 5.11 The psh instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000023 000006 000102 001777 000100 0000 000024 INSTRUCTIONS : 0000000000000110 EXPLANATION : rts pul OCTAL CODE : 000006 pul FUNCTION CODE : pul OPCODE GROUP : group 2 ADDRESSING MODE : none MAIN MEMORY OPERAND : none ACCESS LOCATION : 1776 1730 000000 000000 000000 000000 1734 000000 000000 000000 000000 `pop' data from stack 1776 1740 000000 000000 000000 000000 to acc. 1744 000000 000000 000000 000000 1750 000000 000000 000000 000000 1754 000000 000000 000000 000000 1760 000000 000000 000000 000000 1764 000000 000000 000000 000000 Press q for exit and any other 1770 000000 000000 000000 000000 key for next instruction: 1774 000000 000023 000102 000101 Fig 5.12 The pul instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000100 000015 000020 001774 001774 0000 000101 INSTRUCTIONS : 0000000000001101 EXPLANATION : jsr,#,100 spi OCTAL CODE : 000015 lda,x,3 FUNCTION CODE : spi OPCODE GROUP : group 2 ADDRESSING MODE : none MAIN MEMORY OPERAND : none ACCESS LOCATION : 1774 1730 000000 000000 000000 000000 1734 000000 000000 000000 000000 copy stack pointer 1774 1740 000000 000000 000000 000000 to index register. 1744 000000 000000 000000 000000 1750 000000 000000 000000 000000 1754 000000 000000 000000 000000 1760 000000 000000 000000 000000 1764 000000 000000 000000 000000 Press q for exit and any other 1770 000000 000000 000000 000000 key for next instruction: 1774 000000 000000 000020 000060 Fig 5.13 The spi instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000004 000013 000020 001775 000060 0000 000005 INSTRUCTIONS : 0000000000001011 EXPLANATION : psh sti OCTAL CODE : 000013 jsr,#,100 FUNCTION CODE : sti OPCODE GROUP : group 2 ADDRESSING MODE : none MAIN MEMORY OPERAND : none ACCESS LOCATION : 1775 1730 000000 000000 000000 000000 1734 000000 000000 000000 000000 store index register 1740 000000 000000 000000 000000 to stack 1775 1744 000000 000000 000000 000000 1750 000000 000000 000000 000000 1754 000000 000000 000000 000000 1760 000000 000000 000000 000000 1764 000000 000000 000000 000000 Press q for exit and any other 1770 000000 000000 000000 000000 key for next instruction: 1774 000000 000060 000020 000060 Fig 5.14 The sti instruction \end{verbatim} \newpage \dspaceon Outputs for {\it psh} and {\it pul} are similar. There is no obvious difference between Fig 5.11 and Fig 5.12 except the comment lines. The comments for {\it psh} is {\it push value of acc to stack 1777}. So both acc and location 1777 are highlighted for checking. The comments for {\it pul} is {\it `pop' value from stack 1776 to acc}. They are opposite to each other. \\ \\ The operation of {\it inc}, {\it spi}, {\it rir}, {\it sti} will be associated with index register which, therefore, is highlighted for attention or checking. As for {\it sti} and {\it rir}, accessed locations of the stack are also highlighted. Fig 5.13, shows the result of {\it spi}: the location number 1774 and also the stack pointer, which is stored in the index register. Fig 5.14 is the output of {\it sti}, in which the contents of 1776 is copied to index register. \\ \\ Through the previous examples, we know the explanation for group 2 is simple, but the comments are rather complicated for some function codes, and special attention is required frequently. But seen from another angle, it is beneficial for effective learning. \section{Output of Group 3} All the output of instructions which have function codes of group 3 is almost the same. No addressing mode, no memory location is accessed, and both the psw and the new pc are highlighted for special attention to judge if a branch will happen. \\ \\ For example, if the current instruction is {\it bcs}, the output is as in Fig 5.15. We can see the carry bit (C-bit) is set, so the new pc points to 70. It means a branch will happen and the next instruction to be executed is in location 70. \\ \\ If the current instruction is {\it beq}, then the output is as in Fig 5.16. >From the comment, we know that if Z-bit set, it will branch to 2. On the screen, we can see Z is clear, so no branch will happen and the new pc points to 6, after the current one. \newpage \dspaceoff \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000062 174070 000037 001774 001774 1001 000070 INSTRUCTIONS : 1111100000111000 EXPLANATION : lsr bcs,70 OCTAL CODE : 174070 cmp,#,12 FUNCTION CODE : bcs OPCODE GROUP : group 3 ADDRESSING MODE : none MAIN MEMORY OPERAND : 70 ACCESS LOCATION : none 1730 000000 000000 000000 000000 1734 000000 000000 000000 000000 branch to 70 if C set. 1740 000000 000000 000000 000000 1744 000000 000000 000000 000000 1750 000000 000000 000000 000000 1754 000000 000000 000000 000000 1760 000000 000000 000000 000000 1764 000000 000000 000000 000000 Press q for exit and any other 1770 000000 000000 000000 000000 keys for next instruction: 1774 000000 000000 000020 000060 Fig 5.15 The bcs instruction \end{verbatim} \newpage \vspace*{60mm} \begin{verbatim} pc= instr= acc= sp= index= CNZV= pc<- 000005 100002 000000 002000 000000 0000 000006 INSTRUCTIONS : 1000000000000010 EXPLANATION : sub,d,70 beq,2 OCTAL CODE : 100002 sub,d,71 FUNCTION CODE : beq OPCODE GROUP : group 3 ADDRESSING MODE : none MAIN MEMORY OPERAND : 2 ACCESS LOCATION : none 54 000000 000000 000000 000000 60 012071 100063 000000 102061 branch to 2 if Z set. 64 000000 000000 000000 000000 70 000101 001000 000200 000000 74 000000 000000 000000 000000 100 000000 000000 000000 000000 104 000000 000000 000000 000000 110 000000 000000 000000 000000 Press q for exit and any other 114 000000 000000 000000 000000 key for next instruction: 120 000000 000000 000000 000000 Fig 5.16 The beq instruction \end{verbatim} \newpage \dspaceon \section{Conclusion} The most valuable characteristics of the CAL tool is the format of output, which makes it act as an informative, impressive and effective teaching tool. Furthermore, the contents and format of output are deliberately designed for the objectives of this project, so it is worth while to understand and exploit the output thoroughly. Output from some other function codes are contained in the appendix B of this report for reference.