Utilities for Mano's Basic Computer |
Links on this page: |
|
Dr. M. Moris Mano describes a basic computer in his
textbook, This computer is a toy computer, but serves to present
many of the basic concepts The sample programs I have included in this tutorial |
Other Links: |
| Code |
Pseudo-code |
Nearer assembly language |
Comments |
| // date: Aug 8, 2012 // author: Nicholas Duchon // purpose: write an ascii string // in Mano basic computer // use: put the address of the // start of the string into AC, // -- String must end with a dot! // example of calling routine ORG 10 LDA STRLOC BSA WRTSTR HLT STRLOC HEX STRING // string addr STRING STR "ONE." // subroutine to write a string ORG 100 WRTSTR HEX 0 STA WRTSTRA // save str WRTSTR0 LDA WRTSTRA I // get word CIR // get high byte CIR CIR CIR CIR CIR CIR CIR AND BYTEMASK // see 1 byte ADD WRTSTRDOTN // dot? SZA BUN WRTSTR1 // not dot BUN WRTSTR I // dot > ret WRTSTR1 ADD WRTSTRDOT // restore OUT // write LDA WRTSTRA I // for low AND BYTEMASK // see 1 byte ADD WRTSTRDOTN // dot? SZA BUN WRTSTR2 // not dot BUN WRTSTR I dot > ret WRTSTR2 ADD WRTSTRDOT // restore OUT // write ISZ WRTSTRA // next word BUN WRTSTR0 // loop WRTSTRA HEX 0 WRTSTRDOT CHR '.' WRTSTRDOTN HEX FFD2 BYTEMASK HEX FF |
WRTSTR (strlocation) while true get char if char = dot return else write char end while end subroutine |
WRTSTR <return address
here> AC -> WRTSTRA <string pointer> // effectively i=0 loop: load AC with str[i] CIR x 8, move high byte to low mask ff, remove high byte add ascii for -dot if 0, return add ascii dot,restoring char write char load AC with str[i] mask ff // now low byte add ascii -dot if 0 return add ascii dot, restore char write char i < i+1 // next 2 chars go to loop |
A string is defined using the STR assembler
directive, and for this subroutine to work correctly, the
string should end with a dot (period). Since the computer uses 16-bit words, a string is packed 2 ASCII characters per word, so the subroutine needs to first print the upper byte, then the lower byte. Also the subroutine needs to check each byte to see if it is the dot, which will indicate the end of the string, and will not be printed. In the calling routine, the address of the start of the string must be placed in AC as the input parameter to the subroutine. Again because of the limitations of the machine language of Mano's computer, another labelled word needs to be declared which will hold the address of the start of the string, such as STRLOC in the example program. |
| Code |
Comments |
| // testing stacks: push, pop // also testing WRTSTR ORG 10 CLA INC INC BSA STKPUSH // 1 INC BSA STKPUSH // 2 INC BSA STKPUSH // 3 INC BSA STKPUSH // 4 INC BSA STKPUSH // 5 INC BSA STKPUSH // 6 INC BSA STKPUSH // 7 INC BSA STKPUSH // 8 BSA STKPOP // 8 OUT BSA STKPOP // 7 OUT BSA STKPOP // 6 OUT BSA STKPOP // 5 OUT BSA STKPOP // 4 OUT BSA STKPOP // 3 OUT BSA STKPOP // 2 OUT BSA STKPOP // 1 OUT BSA STKPOP // 0 OUT BSA STKPOP // -1 OUT HLT |
This code will push 8 numbers onto the stack,
then try to pop 10. The pop subroutine should complain when
trying to pop the 9th element and halt the simulation. After
each element is popped, the code will write the value of the
element to the output, as a hex number, so to see the
results, the output panel should be set to hex rather than
ASCII. The first number pushed is 2, then 3, 4, 5, 6, 7, 8 and 9, just to make the numbers a little interesting in the test. |