Character codes: Difference between revisions

Content deleted Content added
Puppydrum64 (talk | contribs)
Puppydrum64 (talk | contribs)
Line 2,601: Line 2,601:
<lang XPL0>IntOut(0, ^a); \(Integer Out) displays "97" on the console (device 0)
<lang XPL0>IntOut(0, ^a); \(Integer Out) displays "97" on the console (device 0)
ChOut(0, 97); \(Character Out) displays "a" on the console (device 0)</lang>
ChOut(0, 97); \(Character Out) displays "a" on the console (device 0)</lang>

=={{header|Z80 Assembly}}==
The Z80 doesn't understand what ASCII codes are by itself. Most computers/systems that use it will have firmware that maps each code to its corresponding glyph. Printing a character given its code is trivial. On the Amstrad CPC:
<lang z80>LD A,'a'
call &BB5a</lang>

Printing a character code given a character takes slightly more work. You'll need to separate each hexadecimal digit of the ASCII code, convert each digit to ASCII, and print it. Once again, thanks to Keith of [http://www.chibiakumas.com] for this code:
<lang z80>ShowHex:
push af
and %11110000
rrca
rrca
rrca
rrca
call PrintHexChar
pop af
and %00001111
;call PrintHexChar (execution flows into it naturally)
PrintHexChar:
or a ;Clear Carry Flag
daa
add a,&F0
adc a,&40 ;this sequence of instructions converts a single hex digit to ASCII.

jp PrintChar ;this is whatever routine prints to the screen on your system.
; It must end in a "ret" and it must take the accumulator as its argument.</lang>


=={{header|Zig}}==
=={{header|Zig}}==