CODINGLISTINGS ★ HEXADECIMAL REVEALED ...IN DECIMAL|COMPUTING WITH THE AMSTRAD) ★

Hexadecimal revealed ...in decimal (Computing with the Amstrad)Coding Listings
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

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

★ PUBLISHER: Computing with the Amstrad
★ YEAR: 1986
★ CONFIG: ???
★ LICENCE: LISTING
★ AUTHOR: Trevor Roberts

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Hexadecimal  Revealed  in  Decimal    (Computing  with  the  Amstrad)    ENGLISH    LISTINGDATE: 2020-07-23
DL: 6 fois
TYPE: PDF
SIZE: 69Ko
NOTE: 1 page/PDFlib v1.6

Je participe au site:
» Newfile(s) upload/Envoye de fichier(s)
★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):

QUE DIT LA LOI FRANÇAISE:

L'alinéa 8 de l'article L122-5 du Code de la propriété intellectuelle explique que « Lorsque l'œuvre a été divulguée, l'auteur ne peut interdire la reproduction d'une œuvre et sa représentation effectuées à des fins de conservation ou destinées à préserver les conditions de sa consultation à des fins de recherche ou détudes privées par des particuliers, dans les locaux de l'établissement et sur des terminaux dédiés par des bibliothèques accessibles au public, par des musées ou par des services d'archives, sous réserve que ceux-ci ne recherchent aucun avantage économique ou commercial ». Pas de problème donc pour nous!

CPCrulez[Content Management System] v8.7-desktop/cache
Page créée en 204 millisecondes et consultée 63 fois

L'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.