THIS month we enter the world of machine code - with a routine that displays a hexadecimal number in decimal. It's a crude version of Basic's PEEK and should hold no fears for those who've been following Mike Bibby's machine code course. Either Mike's Hexer or Roland Waddilove's assembler RAW can be used to enter the code. In fact you can test your skill by improving the routine. After all why SUB when you can CP? - 8000 Here the code begins with the A register being loaded with the number. Since I've been using RAW I've just used a label, number. In practice the number would probably be loaded from a location into the A register.
- 8002 The C register is to be used as a counter, keeping track of the number of times that 100. 10 or 1 can be subtracted from number until the result in the A register is negative. However instead of going up 0, 1, 2 and so on as is usual, this counter starts at &30 and carries on from there. The reason for this is that charout, the routine that will display the results, uses Ascii values. And &30 is the Ascii for 0.
- 8004 Now the code tries to figure out how many hundreds number contains. It does this by repeatedly subtracting 100 (&64) from number.
- 8006 For each subtraction of 100, the C register has its contents increased by 1.
- 8007 Tests the carry flag. If it is set. then the subtraction has resulted in a negative number in the A register and the micro goes on to the subsequent instruction. If it's not set then the JR NC sends the Amstrad back to subtract another hundred.
- 8009 To leave the loop the program has "overshot" the number of subtractions. The C register will reflect this, counting the final 100 that took the A register over the edge. This has to be undone, so the C register is decremented by 1.
- 800A When the loop has finished the A register contains a negative number because the final 100 subtracted took number "round the clock”. This must be added back again to give the tens and units part of number.
- 800C What's left of number is tucked away in the B register for safe keeping.
- 800D The contents of C are transferred to the A register.
- 800E The system's own machine code routine displays the character whose Ascii code is held in the A register. In this case it's the number of hundreds in the original number.
- 8011 The C register counter is initialised again.
- 8013 The contents of the B register (the remnants of number) are restored to the A register for more operations.
- 8014-801E Now the code follows the same procedure except that it is 10 that is subtracted, not 100. Again the C register keeps track of the number of times that 10 can be taken away. The overshoot is corrected, the remaining units tucked away and the contents of C are transferred to the A register for charout to show to the world.
- 8021 -8023 These retrieve the units from their sanctuary in the B register and reset the counter in the C register.
- 8024-802B The units are counted in exactly the same way and displayed via charout. The only difference is that now the B register is no longer used to store the leftover bits of number. There are none. Can you use a JP NZ instruction here instead of JR NC? And if you can. do you need to decrement the C register?
- 802E The routine returns whence it was CALLed.
CWTA ★ AMSTRAD CPC ★ DOWNLOAD ★ |
|
CPCrulez[Content Management System] v8.732-desktop Page créée en 029 millisecondes et consultée 1071 foisL'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko. |
|
|