Show ASCII table: Difference between revisions
→{{header|langur}}
No edit summary |
Langurmonkey (talk | contribs) |
||
(47 intermediate revisions by 26 users not shown) | |||
Line 11:
{{trans|Python}}
<
L(j) (32 + i .. 127).step(16)
String k
Line 21:
k = Char(code' j)
print(‘#3 : #<3’.format(j, k), end' ‘’)
print()</
{{out}}
Line 44:
=={{header|6502 Assembly}}==
<
; task : show ascii table
; language: 6502 Assembly
Line 163:
column .byte 0
ascii .byte 0
</syntaxhighlight>
=={{header|8080 Assembly}}==
<
mvi a,32 ; Start with space
mvi d,16 ; 16 lines
Line 234:
spc: db 'Spc ',0 ; Space
del: db 'Del ',0 ; Del
chr: db '* ',0 ; Placeholder for character</
{{out}}
Line 258:
=={{header|8086 Assembly}}==
<
bits 16
putch: equ 2h
Line 315:
spc: db 'Spc ',0 ; Space
del: db 'Del ',0 ; Del
chr: db '* ',0 ; Placeholder for character</
{{out}}
Line 338:
=={{header|Action!}}==
Atari 8-bit computers use [https://en.wikipedia.org/wiki/ATASCII ATASCII] character set which is a variation of ASCII.
<
BYTE
count=[96],rows=[16],
Line 372:
PutE()
OD
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Show_ASCII_table.png Screenshot from Atari 8-bit computer]
Line 395:
=={{header|Ada}}==
<
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
Line 417:
New_Line;
end loop;
end Ascii_Table;</
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 437:
=={{header|ALGOL 68}}==
<
FOR c FROM 32 TO 32 + 15 DO
FOR
print( ( whole(
, ": "
, IF
ELIF
ELSE " " + REPR
FI
)
)
OD;
</syntaxhighlight>
{{out}}
<pre> 32: SPC
</pre>
=={{header|ALGOL W}}==
This assumes the ASCII character set is used by the Algol W compiler/runtime - the original Algol W implementation used EBCDIC.
<syntaxhighlight
for i := 32 until 32 + 15 do begin
for
end for_ach
end for_i.
</syntaxhighlight>
{{out}}
<pre>
47: / 63: ? 79: O 95: _ 111: o 127: Del
</pre>
=={{header|APL}}==
<
{{out}}
Line 527 ⟶ 529:
=={{header|AppleScript}}==
<
on asciiTable()
script row
Line 782 ⟶ 784:
set my text item delimiters to dlm
str
end unlines</
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 802 ⟶ 804:
=={{header|Applesoft BASIC}}==
This is similar to the Commodore BASIC program in that it clears the screen and displays the version of BASIC. It uses enterable Applesoft BASIC to embed a 6502 machine language routine that XORs $87 with the character stored at $41 and prints the character.<
10 LET X = 256 * PEEK (104)
11 LET X = X + PEEK (103) + 7
Line 821 ⟶ 823:
70 LET N$ = RIGHT$ (N$,4)
80 PRINT N$":" CHR$ (A + R);
90 NEXT C,R: PRINT</
The 6502 routine is embedded at line 0 and is used to display the string "!TFOSORCIM" backwards.
<
EOR #$87 ; I READ
JMP $DB59 ; LY RND</
=={{header|ARM Assembly}}==
Thanks to Keith of [https://www.chibiakumas.com ChibiAkumas] for creating the GBA bitmap font and I/O routines.
<
.equ CursorY,0x02000001
ProgramStart:
Line 1,117 ⟶ 1,119:
.byte 0x00,0x00,0x00,0x20,0x52,0x0C,0x00,0x00 ; 7E ~
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; 7F
.byte 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ; 80</
{{out}}
Line 1,124 ⟶ 1,126:
=={{header|Arturo}}==
<
k: ø
case [num]
Line 1,133 ⟶ 1,135:
prints pad ~"|num|: |k|" 10
if 1 = num%6 -> print ""
]</
{{out}}
Line 1,155 ⟶ 1,157:
=={{header|AutoHotkey}}==
<
MessageText := ;The text to display in the final message box.
Line 1,184 ⟶ 1,186:
}
MsgBox, % MessageText ;Displays a message box with the ASCII conversion table, from the MessageText variable
return</
{{out}}
<pre>
Line 1,207 ⟶ 1,209:
{{works with|GAWK}}
{{works with|MAWK}}
<
# syntax: MAWK -f SHOW_ASCII_TABLE.AWK
BEGIN {
Line 1,219 ⟶ 1,221:
print ""
}
}</
{{out}}
<pre> 32: SPC 48: 0 64: @ 80: P 96: ` 112: p
Line 1,239 ⟶ 1,241:
=={{header|BASIC}}==
==={{header|BASIC256}}===
<syntaxhighlight lang="vb">for i = 32 to 47
for j = i to i + 80 step 16
begin case
case j = 32
s$ = "Spc"
case j = 127
s$ = "Del"
else
s$ = chr(j)
end case
print rjust(" "+string(j),5); ": "; ljust(s$,3);
next j
print
next i</syntaxhighlight>
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">10 cls
20 for r = 0 to 15
30 for c = 1 to 6
40 a = 16+r+c*16
50 print right$(" "+str$(a),4)": " chr$(a)tab (10*c);
60 next c
70 print
80 next r</syntaxhighlight>
{{out}}
<pre> 32: 48: 0 64: @ 80: P 96: ` 112: p
33: ! 49: 1 65: A 81: Q 97: a 113: q
34: " 50: 2 66: B 82: R 98: b 114: r
35: # 51: 3 67: C 83: S 99: c 115: s
36: $ 52: 4 68: D 84: T 100: d 116: t
37: % 53: 5 69: E 85: U 101: e 117: u
38: & 54: 6 70: F 86: V 102: f 118: v
39: ' 55: 7 71: G 87: W 103: g 119: w
40: ( 56: 8 72: H 88: X 104: h 120: x
41: ) 57: 9 73: I 89: Y 105: i 121: y
42: * 58: : 74: J 90: Z 106: j 122: z
43: + 59: ; 75: K 91: [ 107: k 123: {
44: , 60: < 76: L 92: \ 108: l 124: |
45: - 61: = 77: M 93: ] 109: m 125: }
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: ⌂</pre>
==={{header|GW-BASIC}}===
{{works with|BASICA}}
<syntaxhighlight lang="gwbasic">10 DEFINT I,J: DEFSTR S: DIM S(2)
20 S(0)="* "
30 S(1)="Spc"
Line 1,249 ⟶ 1,298:
90 NEXT J
100 PRINT
110 NEXT I</
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 1,267 ⟶ 1,316:
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: Del</pre>
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 TEXT 80
110 FOR R=0 TO 15
120 FOR C=32+R TO 112+R STEP 16
130 PRINT USING "###":C;:PRINT ": ";CHR$(C),
140 NEXT
150 PRINT
160 NEXT</syntaxhighlight>
==={{header|MSX Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
==={{header|QBasic}}===
The [[#QB64|QB64]] solution works without any changes.
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
<syntaxhighlight lang="vb">for i = 32 to 47
for j = i to i + 80 step 16
select case j
case 32
s$ = "Spc"
case 127
s$ = "Del"
case else
s$ = chr$(j)
end select
print right$(" "+str$(j),4); ": "; s$; space$(3);
next j
print
next i</syntaxhighlight>
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">FOR i = 32 TO 47
FOR j = i TO i+80 STEP 16
SELECT CASE j
CASE 32
LET s$ = "Spc"
CASE 127
LET s$ = "Del"
CASE else
LET s$ = CHR$(j)
END SELECT
PRINT USING "###: ### ": j, s$;
NEXT j
PRINT
NEXT</syntaxhighlight>
{{out}}
<pre>Same as QB64 entry.</pre>
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "ASCII table"
VERSION "0.0000"
DECLARE FUNCTION Entry ()
FUNCTION Entry ()
FOR i = 32 TO 47
FOR j = i TO i + 80 STEP 16
SELECT CASE j
CASE 32
s$ = "Spc"
CASE 127
s$ = "Del"
CASE ELSE
s$ = CHR$(j)
END SELECT
PRINT RJUST$(" "+STRING(j),4); ": "; LJUST$(s$,3);
NEXT j
PRINT
NEXT i
END FUNCTION
END PROGRAM</syntaxhighlight>
==={{header|Yabasic}}===
<syntaxhighlight lang="vb">for i = 32 to 47
for j = i to i + 80 step 16
s$ = chr$(j)
if j = 32 s$ = "Spc"
if j = 127 s$ = "Del"
print str$(j, "#####"), ": ", s$;
next j
print
next i</syntaxhighlight>
=={{header|BaCon}}==
<
FOR i = 32+j TO 127 STEP 16
PRINT i FORMAT " %3d - ";
Line 1,282 ⟶ 1,418:
NEXT
PRINT
NEXT</
{{out}}
Line 1,303 ⟶ 1,439:
=={{header|BCPL}}==
<
let str(n) =
Line 1,315 ⟶ 1,451:
writef(str(j), j, j)
wrch('*N')
$)</
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 1,333 ⟶ 1,469:
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: Del</pre>
=={{header|BQN}}==
The final result is a 2D array of characters which is output line by line with <code>•Out</code>.
<syntaxhighlight lang="bqn">chs←⟨"SPC"⟩∾(@+33+↕94)∾⟨"DEL"⟩
J←{𝕨∾' '∾𝕩}´
_pad←{(𝕗×·⌈´≠¨)⊸(↑¨)}
•Out˘J˘J¨⍉6‿16⥊<˘⍉(∾⟜':'¨¯1 _pad •Fmt¨32+↕96)≍1 _pad chs</syntaxhighlight>
<syntaxhighlight lang="text"> 32: SPC 48: 0 64: @ 80: P 96: ` 112: p
33: ! 49: 1 65: A 81: Q 97: a 113: q
34: " 50: 2 66: B 82: R 98: b 114: r
35: # 51: 3 67: C 83: S 99: c 115: s
36: $ 52: 4 68: D 84: T 100: d 116: t
37: % 53: 5 69: E 85: U 101: e 117: u
38: & 54: 6 70: F 86: V 102: f 118: v
39: ' 55: 7 71: G 87: W 103: g 119: w
40: ( 56: 8 72: H 88: X 104: h 120: x
41: ) 57: 9 73: I 89: Y 105: i 121: y
42: * 58: : 74: J 90: Z 106: j 122: z
43: + 59: ; 75: K 91: [ 107: k 123: {
44: , 60: < 76: L 92: \ 108: l 124: |
45: - 61: = 77: M 93: ] 109: m 125: }
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: DEL</syntaxhighlight>
=={{header|Brainf***}}==
{{trans|M2000 Interpreter}}
<syntaxhighlight lang="bf">
> ++++++ ; 6 rows
> ++++ ++++ ++++ ++++ ; 16 columns
> ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ; 32: the starting character
<< ; move to row counter
[
> ; move to the column counter
[> ; move to character
. ; print it
+ ; increase it
<- ; decrease the column counter
]
+++++ +++++.[-] ; print newline
++++ ++++ ++++ ++++ ; set column counter again
<-] ; decrease row counter and loop
</syntaxhighlight>
{{out}}
<pre>
!"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~
</pre>
=={{header|C}}==
{{trans|Go}}
<
int main() {
Line 1,353 ⟶ 1,543:
}
return 0;
}</
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 1,373 ⟶ 1,563:
=={{header|C++}}==
<
#include <iomanip>
#include <iostream>
inline constexpr auto HEIGHT = 16;
inline constexpr auto ASCII_START = 32;
// ASCII special characters
inline constexpr auto SPACE = 32;
inline constexpr auto DELETE = 127;
std::string displayAscii(
switch (ascii) {
case SPACE: return "Spc";
case DELETE: return "
default: return std::string(1, ascii);
}
int main(
for (std::size_t row = 0; row < HEIGHT; ++row) {
for (
std::cout << std::right << std::setw(3) << ascii << " : " << std::left << std::setw(6) << displayAscii(ascii);
}
}
}</syntaxhighlight>
{{out}}
<pre>
Line 1,429 ⟶ 1,612:
=={{header|C sharp}}==
<
using static System.Linq.Enumerable;
Line 1,442 ⟶ 1,625:
string Text(int index) => index == 32 ? "Sp" : index == 127 ? "Del" : (char)index + "";
}
}</
{{out}}
<pre> 32 : Sp 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 1,462 ⟶ 1,645:
=={{header|Caché ObjectScript}}==
<
; this is 96 characters, so do 6 columns of 16
for i = 32:1:127 {
Line 1,479 ⟶ 1,662:
}
quit</
{{out}}
Line 1,506 ⟶ 1,689:
Further down, the code will be modified to handle the more general case of a grid where the number of codes to be displayed doesn't match the product of the numbers of rows and columns in the desired grid. That case is made a little trickier by the desire to print the table in "column-major order", which seems the friendlier to the end-user reading the table.
<syntaxhighlight lang="clojure">
(defn cell [code]
(let [text (get {32 "Spc", 127 "Del"} code (char code))]
Line 1,525 ⟶ 1,708:
(defn pr-ascii-table [n-cols st-code end-code]
(println (ascii-table n-cols st-code end-code)))
</syntaxhighlight>
{{out}}
Line 1,571 ⟶ 1,754:
There are 2 output examples, the first simply creates a grid with an incomplete final column. The second case additionally demonstrates the ability to modify the range of ASCII codes displayed.
<syntaxhighlight lang="clojure">
(defn cell [code]
(if (nil? code)
Line 1,594 ⟶ 1,777:
(defn pr-ascii-table [n-cols st-code end-code]
(println (ascii-table n-cols st-code end-code)))
</syntaxhighlight>
{{out}}
Line 1,634 ⟶ 1,817:
=={{header|CLU}}==
<
if n=32 then return("Spc")
elseif n=127 then return("Del")
Line 1,651 ⟶ 1,834:
stream$putl(po, "")
end
end start_up</
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 1,673 ⟶ 1,856:
{{works with|OpenCOBOL|3.1.2}}
Uses free form syntax.
<syntaxhighlight lang="cobol">
IDENTIFICATION DIVISION.
PROGRAM-ID. CHARSET.
Line 1,696 ⟶ 1,879:
END-PERFORM.
END PROGRAM CHARSET.
</syntaxhighlight>
{{out}}
Line 1,704 ⟶ 1,887:
=={{header|Commodore BASIC}}==
<
110 PRINT CHR$(14);:REM CHARACTER SET 2
120 PRINT "COMMODORE 64 - BASIC V2"
Line 1,716 ⟶ 1,899:
200 PRINT
210 NEXT R
</syntaxhighlight>
{{out}}
[[File:c64asciitable.jpg]]
Line 1,723 ⟶ 1,906:
=={{header|Common Lisp}}==
<
(setq endVal 127)
(setq cols 6)
Line 1,740 ⟶ 1,923:
(if (> lower upper) '() (cons lower (get-range (+ 1 lower) upper))))
(mapcar #'print-val (get-range startVal endVal))</
{{out}}
<pre> 32: SPC 33: ! 34: " 35: # 36: $ 37: %
Line 1,760 ⟶ 1,943:
=={{header|Cowgol}}==
<
# Print number with preceding space if <100 and trailing colon
Line 1,792 ⟶ 1,975:
end if;
end loop;
print_nl();</
{{out}}
Line 1,815 ⟶ 1,998:
=={{header|D}}==
{{trans|C}}
<
void main() {
Line 1,834 ⟶ 2,017:
writeln;
}
}</
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 1,857 ⟶ 2,040:
{{Works with|GNU dc|1.3.95}}
<
## for initcode condcode incrcode body
Line 1,888 ⟶ 2,071:
] lfx
[]pP
] lfx</
{{out}}
<pre>
Line 1,912 ⟶ 2,095:
{{Trans|Go}}
<syntaxhighlight lang="delphi">
program Show_Ascii_table;
Line 1,943 ⟶ 2,126:
end.
</syntaxhighlight>
{{out}}
Line 1,964 ⟶ 2,147:
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
</pre>
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc write_item(byte n) void:
*char chrstr = "* ";
chrstr* := pretend(n, char);
write(n:3, " : ",
case n
incase 32: "Spc "
incase 127: "Del "
default: chrstr
esac)
corp
proc main() void:
byte row, col;
for row from 32 upto 47 do
for col from row by 16 upto 127 do
write_item(col)
od;
writeln()
od
corp</syntaxhighlight>
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r
35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s
36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t
37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u
38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v
39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w
40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x
41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y
42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z
43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : {
44 : , 60 : < 76 : L 92 : \ 108 : l 124 : |
45 : - 61 : = 77 : M 93 : ] 109 : m 125 : }
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del</pre>
=={{header|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight lang="easylang">
numfmt 0 3
for i range0 16
for j = 32 + i step 16 to 127
if j = 32
x$ = "Spc"
elif j = 127
x$ = "Del"
else
x$ = strchar j & " "
.
write j & ": " & x$
.
print ""
.
</syntaxhighlight>
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
module ShowAsciiTable {
@Inject Console console;
void run() {
for (Int offset : 0..<16) {
for (Int ascii = 32+offset; ascii < 128; ascii += 16) {
console.print($|{ascii.toString().rightJustify(3)}/\
|{ascii.toByte().toByteArray()}: \
|{new Char(ascii).quoted().leftJustify(5)}
, suppressNewline=True);
}
console.print();
}
}
}
</syntaxhighlight>
{{out}}
<pre>
32/0x20: ' ' 48/0x30: '0' 64/0x40: '@' 80/0x50: 'P' 96/0x60: '`' 112/0x70: 'p'
33/0x21: '!' 49/0x31: '1' 65/0x41: 'A' 81/0x51: 'Q' 97/0x61: 'a' 113/0x71: 'q'
34/0x22: '\"' 50/0x32: '2' 66/0x42: 'B' 82/0x52: 'R' 98/0x62: 'b' 114/0x72: 'r'
35/0x23: '#' 51/0x33: '3' 67/0x43: 'C' 83/0x53: 'S' 99/0x63: 'c' 115/0x73: 's'
36/0x24: '$' 52/0x34: '4' 68/0x44: 'D' 84/0x54: 'T' 100/0x64: 'd' 116/0x74: 't'
37/0x25: '%' 53/0x35: '5' 69/0x45: 'E' 85/0x55: 'U' 101/0x65: 'e' 117/0x75: 'u'
38/0x26: '&' 54/0x36: '6' 70/0x46: 'F' 86/0x56: 'V' 102/0x66: 'f' 118/0x76: 'v'
39/0x27: '\'' 55/0x37: '7' 71/0x47: 'G' 87/0x57: 'W' 103/0x67: 'g' 119/0x77: 'w'
40/0x28: '(' 56/0x38: '8' 72/0x48: 'H' 88/0x58: 'X' 104/0x68: 'h' 120/0x78: 'x'
41/0x29: ')' 57/0x39: '9' 73/0x49: 'I' 89/0x59: 'Y' 105/0x69: 'i' 121/0x79: 'y'
42/0x2A: '*' 58/0x3A: ':' 74/0x4A: 'J' 90/0x5A: 'Z' 106/0x6A: 'j' 122/0x7A: 'z'
43/0x2B: '+' 59/0x3B: ';' 75/0x4B: 'K' 91/0x5B: '[' 107/0x6B: 'k' 123/0x7B: '{'
44/0x2C: ',' 60/0x3C: '<' 76/0x4C: 'L' 92/0x5C: '\\' 108/0x6C: 'l' 124/0x7C: '|'
45/0x2D: '-' 61/0x3D: '=' 77/0x4D: 'M' 93/0x5D: ']' 109/0x6D: 'm' 125/0x7D: '}'
46/0x2E: '.' 62/0x3E: '>' 78/0x4E: 'N' 94/0x5E: '^' 110/0x6E: 'n' 126/0x7E: '~'
47/0x2F: '/' 63/0x3F: '?' 79/0x4F: 'O' 95/0x5F: '_' 111/0x6F: 'o' 127/0x7F: '\d'
</pre>
=={{header|Excel}}==
===LAMBDA===
Line 1,972 ⟶ 2,253:
{{Works with|Office 365 betas 2021}}
<
=LAMBDA(i,
justifyRight(3)(" ")(i) & ": " & (
Line 1,989 ⟶ 2,270:
)(
SEQUENCE(16, 6, 32, 1)
)</
and also assuming the following generic binding in the Name Manager for the WorkBook:
<
=LAMBDA(n,
LAMBDA(c,
Line 2,011 ⟶ 2,292:
)
)
)</
{{Out}}
Line 2,189 ⟶ 2,470:
Or, separating code and character into adjacent Excel cells:
<
=LAMBDA(i,
IF(0 <> MOD(i, 1),
Line 2,207 ⟶ 2,488:
)(
SEQUENCE(16, 12, 32, 0.5)
)</
{{Out}}
Line 2,491 ⟶ 2,772:
===Idiomatic version===
{{Works with|Factor|0.98}}
<
pair-rocket sequences ;
IN: rosetta-code.ascii-table
Line 2,505 ⟶ 2,786:
: print-ascii-table ( -- ) 16 <iota> [ print-row ] each ;
MAIN: print-ascii-table</
===Go translation===
{{Trans|Go}}
{{Works with|Factor|0.98}}
<
pair-rocket sequences ;
IN: rosetta-code.ascii-table
Line 2,527 ⟶ 2,808:
;
MAIN: main</
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 2,548 ⟶ 2,829:
=={{header|Forth}}==
Idiomatic Forth version is factored differently than conventional languages, allowing each factor to be tested independently at the console, bottom up.
<
: ###: ( c -- ) 3 .R ." : " ;
Line 2,564 ⟶ 2,845:
: ASCII.TABLE ( -- )
16 0 DO 113 I + 32 I + .ROW LOOP ;</
Test Output at the console
<
32: spc 48: 0 64: @ 80: P 96: ` 112: p
33: ! 49: 1 65: A 81: Q 97: a 113: q
Line 2,584 ⟶ 2,865:
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: del ok
</syntaxhighlight>
Line 2,592 ⟶ 2,873:
The dollar sign $ in the format string isn't part of the standard but is a common extension.
ACHAR may not be part of the standard, either.
<
IMPLICIT NONE
INTEGER I, J
Line 2,616 ⟶ 2,897:
END
</syntaxhighlight>
output:
<pre> 32:Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 2,639 ⟶ 2,920:
=={{header|FreeBASIC}}==
<
if n=32 then return "Spc"
if n=127 then return "Del"
Line 2,660 ⟶ 2,941:
print disp
next r
</syntaxhighlight>
{{out}}
Line 2,684 ⟶ 2,965:
=={{header|Free Pascal}}==
<
// (except in ISO-compliant “compiler modes”).
program showAsciiTable(output);
Line 2,745 ⟶ 3,026:
end;
end;
end.</
{{out}}
Line 2,766 ⟶ 3,047:
</pre>
=={{header|Frink}}==
<syntaxhighlight lang="frink">a = ["32 Space"]
for i = 33 to 126
a.push["$i " + char[i]]
a.push["127 Delete"]
println[formatTableBoxed[columnize[a,8].transpose[], "left"]]</syntaxhighlight>
{{out}}
<pre>
┌────────┬────┬────┬────┬────┬────┬────┬────┬─────┬─────┬─────┬──────────┐
│32 Space│40 (│48 0│56 8│64 @│72 H│80 P│88 X│96 ` │104 h│112 p│120 x │
├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤
│33 ! │41 )│49 1│57 9│65 A│73 I│81 Q│89 Y│97 a │105 i│113 q│121 y │
├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤
│34 " │42 *│50 2│58 :│66 B│74 J│82 R│90 Z│98 b │106 j│114 r│122 z │
├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤
│35 # │43 +│51 3│59 ;│67 C│75 K│83 S│91 [│99 c │107 k│115 s│123 { │
├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤
│36 $ │44 ,│52 4│60 <│68 D│76 L│84 T│92 \│100 d│108 l│116 t│124 | │
├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤
│37 % │45 -│53 5│61 =│69 E│77 M│85 U│93 ]│101 e│109 m│117 u│125 } │
├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤
│38 & │46 .│54 6│62 >│70 F│78 N│86 V│94 ^│102 f│110 n│118 v│126 ~ │
├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤
│39 ' │47 /│55 7│63 ?│71 G│79 O│87 W│95 _│103 g│111 o│119 w│127 Delete│
└────────┴────┴────┴────┴────┴────┴────┴────┴─────┴─────┴─────┴──────────┘
</pre>
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Show_ASCII_table}}
'''Solution'''
[[File:Fōrmulæ - Show ASCII table 01.png]]
[[File:Fōrmulæ - Show ASCII table 02.png]]
=={{header|FutureBasic}}==
<
include "NSLog.incl"
local fn ASCIITable as CFStringRef
NSinteger i
CFStringRef temp
CFMutableStringRef mutStr = fn MutableStringWithCapacity( 0 )
for i = 32 to 127
temp = fn StringWithFormat( @"%c", i )
if i == 32 then temp = @"Spc"
if i ==
MutableStringAppendString( mutStr, fn StringWithFormat( @"%-1d : %@\n", i, temp ) )
next
CFArrayRef colArr = fn StringComponentsSeparatedByString( mutStr, @"\n" )
for i = 0 to 15
ObjectRef col0 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i ) )
ObjectRef
ObjectRef
ObjectRef
ObjectRef
ObjectRef
MutableStringAppendString( mutStr, fn StringWithFormat( @"%-10s %-10s %-10s %-10s %-10s %-10s\n", col0, col1, col2, col3, col4, col5 ) )
next
end fn = fn StringWithString( mutStr )
Line 2,809 ⟶ 3,117:
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Line 2,829 ⟶ 3,137:
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
</pre>
=={{header|Go}}==
<
import "fmt"
Line 2,850 ⟶ 3,157:
fmt.Println()
}
}</
{{out}}
Line 2,873 ⟶ 3,180:
=={{header|Groovy}}==
{{trans|Java}}
<
static void main(String[] args) {
for (int i = 32; i <= 127; i++) {
Line 2,887 ⟶ 3,194:
}
}
}</
{{out}}
<pre> 32: Spc 33: ! 34: " 35: # 36: $ 37: %
Line 2,907 ⟶ 3,214:
=={{header|Haskell}}==
<
import Data.List (transpose)
import Data.List.Split (chunksOf)
Line 2,939 ⟶ 3,246:
--------------------------- TEST -------------------------
main :: IO ()
main = putStrLn asciiTable</
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 2,958 ⟶ 3,265:
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del </pre>
=={{
<syntaxhighlight lang="insitux">
(-> (for i (range 16)
(let k (match j 32 "Spc" 127 "Del" (str (char-code j) " ")))
(strn ((< j 100) " ") j " : " k))
(partition 6)
(map (join " "))
(join "\n"))
</syntaxhighlight>
{{out}}
<pre>
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r
35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s
36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t
37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u
38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v
39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w
40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x
41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y
42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z
43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : {
44 : , 60 : < 76 : L 92 : \ 108 : l 124 : |
45 : - 61 : = 77 : M 93 : ] 109 : m 125 : }
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
</pre>
=={{header|J}}==
<pre> ;"1 (_9{.":,': ',ucp)each 32+|:i.6 16
32: 48: 0 64: @ 80: P 96: ` 112: p
33: ! 49: 1 65: A 81: Q 97: a 113: q
34: " 50: 2 66: B 82: R 98: b 114: r
35: # 51: 3 67: C 83: S 99: c 115: s
</pre>
Note that ascii 127 does not have a standard representation, so its appearance will depend on a variety of issues.
=={{header|Java}}==
<
public class ShowAsciiTable {
Line 3,049 ⟶ 3,337:
}
</syntaxhighlight>
{{out}}
<pre>
Line 3,068 ⟶ 3,356:
116: t 117: u 118: v 119: w 120: x 121: y
122: z 123: { 124: | 125: } 126: ~ 127: Del
</pre>
You could also do this:<br />
<syntaxhighlight lang="java">
String printASCIITable() {
StringBuilder string = new StringBuilder();
String newline = System.lineSeparator();
string.append("dec hex binary oct char").append(newline);
for (int decimal = 32; decimal <= 127; decimal++) {
string.append(format(decimal));
switch (decimal) {
case 32 -> string.append("[SPACE]");
case 127 -> string.append("[DELETE]");
default -> string.append((char) decimal);
}
string.append(newline);
}
return string.toString();
}
String format(int value) {
return "%-3d %01$-2x %7s %01$-3o ".formatted(value, Integer.toBinaryString(value));
}
</syntaxhighlight>
<pre>
dec hex binary oct char
32 20 100000 40 [SPACE]
33 21 100001 41 !
34 22 100010 42 "
35 23 100011 43 #
36 24 100100 44 $
37 25 100101 45 %
38 26 100110 46 &
39 27 100111 47 '
40 28 101000 50 (
41 29 101001 51 )
42 2a 101010 52 *
43 2b 101011 53 +
44 2c 101100 54 ,
45 2d 101101 55 -
46 2e 101110 56 .
47 2f 101111 57 /
48 30 110000 60 0
49 31 110001 61 1
50 32 110010 62 2
51 33 110011 63 3
52 34 110100 64 4
53 35 110101 65 5
54 36 110110 66 6
55 37 110111 67 7
56 38 111000 70 8
57 39 111001 71 9
58 3a 111010 72 :
59 3b 111011 73 ;
60 3c 111100 74 <
61 3d 111101 75 =
62 3e 111110 76 >
63 3f 111111 77 ?
64 40 1000000 100 @
65 41 1000001 101 A
66 42 1000010 102 B
67 43 1000011 103 C
68 44 1000100 104 D
69 45 1000101 105 E
70 46 1000110 106 F
71 47 1000111 107 G
72 48 1001000 110 H
73 49 1001001 111 I
74 4a 1001010 112 J
75 4b 1001011 113 K
76 4c 1001100 114 L
77 4d 1001101 115 M
78 4e 1001110 116 N
79 4f 1001111 117 O
80 50 1010000 120 P
81 51 1010001 121 Q
82 52 1010010 122 R
83 53 1010011 123 S
84 54 1010100 124 T
85 55 1010101 125 U
86 56 1010110 126 V
87 57 1010111 127 W
88 58 1011000 130 X
89 59 1011001 131 Y
90 5a 1011010 132 Z
91 5b 1011011 133 [
92 5c 1011100 134 \
93 5d 1011101 135 ]
94 5e 1011110 136 ^
95 5f 1011111 137 _
96 60 1100000 140 `
97 61 1100001 141 a
98 62 1100010 142 b
99 63 1100011 143 c
100 64 1100100 144 d
101 65 1100101 145 e
102 66 1100110 146 f
103 67 1100111 147 g
104 68 1101000 150 h
105 69 1101001 151 i
106 6a 1101010 152 j
107 6b 1101011 153 k
108 6c 1101100 154 l
109 6d 1101101 155 m
110 6e 1101110 156 n
111 6f 1101111 157 o
112 70 1110000 160 p
113 71 1110001 161 q
114 72 1110010 162 r
115 73 1110011 163 s
116 74 1110100 164 t
117 75 1110101 165 u
118 76 1110110 166 v
119 77 1110111 167 w
120 78 1111000 170 x
121 79 1111001 171 y
122 7a 1111010 172 z
123 7b 1111011 173 {
124 7c 1111100 174 |
125 7d 1111101 175 }
126 7e 1111110 176 ~
127 7f 1111111 177 [DELETE]
</pre>
=={{header|JavaScript}}==
<
"use strict";
Line 3,176 ⟶ 3,585:
// MAIN ---
return asciiTable();
})();</
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 3,196 ⟶ 3,605:
=={{header|Jsish}}==
<
/* Show ASCII table, -showAll true to include control codes */
Line 3,262 ⟶ 3,671:
015 SI 031 US 047 / 063 ? 079 O 095 _ 111 o 127 DEL
=!EXPECTEND!=
*/</
{{out}}
<pre>prompt$ jsish -u showASCIITable.jsi
Line 3,291 ⟶ 3,700:
The following program generalizes the task to produce a table for wide stretches of Unicode characters, not just 32 .. 127. In addition, the functions for producing both row-wise and column-wise tables are provided and illustrated.
<syntaxhighlight lang="jq">
# Pretty printing
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
Line 3,319 ⟶ 3,728:
end
| lpad(4) ;
</syntaxhighlight>
===Base Task===
<
def prepare($m;$n):
[range($m; $n) | "\(lpad(7)): \(humanize)" ];
Line 3,330 ⟶ 3,739:
# Column-wise with 16 rows would be produced by:
# prepare(32;128) | ttable(16)
</syntaxhighlight>
{{out}}
<pre>
Line 3,352 ⟶ 3,761:
===Column-wise table of 128..255===
<syntaxhighlight lang="jq">
# Column-wise representation with 16 rows
(prepare(128;256) | ttable(16))
</syntaxhighlight>
{{out}}
<pre>
Line 3,378 ⟶ 3,787:
=={{header|Julia}}==
===Base Task===
<
c= i== 0 ? "NUL" : i== 7 ? "BEL" : i== 8 ? "BKS" : i== 9 ? "TAB" :
i==10 ? "LF " : i==13 ? "CR " : i==27 ? "ESC" : i==155 ? "CSI" : "|$(Char(i))|"
print("$(lpad(i,3)) $(string(i,base=16,pad=2)) $c")
(i&7)==7 ? println() : print(" ")
end</
<pre>
32 20 | | 33 21 |!| 34 22 |"| 35 23 |#| 36 24 |$| 37 25 |%| 38 26 |&| 39 27 |'|
Line 3,402 ⟶ 3,811:
{{works with|Julia|1.0}}
<
c= i== 0 ? "NUL" : i== 7 ? "BEL" : i== 8 ? "BKS" : i== 9 ? "TAB" :
i==10 ? "LF " : i==13 ? "CR " : i==27 ? "ESC" : i==155 ? "CSI" : "|$(Char(i))|"
print("$(lpad(i,3)) $(string(i,base=16,pad=2)) $c")
(i&7)==7 ? println() : print(" ")
end</
{{out}}
<pre> 0 00 NUL 1 01 |☺| 2 02 |☻| 3 03 |♥| 4 04 |♦| 5 05 |♣| 6 06 |♠| 7 07 BEL
Line 3,445 ⟶ 3,854:
This version draws a more fancy table, positioning the items on the console monitor with ANSI control sequences:
<
print("""
0 1 2 3 4 5 6 7 8 9 A B C D E F
Line 3,469 ⟶ 3,878:
6<i<11 || i==155 || i==173 || print("\e[$r;$(c)H$(Char(i))")
end
print("\e[54;1H")</
{{out}}
<pre> 0 1 2 3 4 5 6 7 8 9 A B C D E F
Line 3,524 ⟶ 3,933:
A similar output can be produced without ANSI control sequences, just filling up a huge string and printing it. Below is a general Object (struct) and the corresponding methods to draw a table of arbitrary shape in the console. It is the Julia way of OOP. The Table structure holds the relevant data and the constructor. The Base.iterate function extends the general iterate function, and allows using the field names in a function, w/o prefixing them with "<structName>." The function prt() fills up a string with data, formatting spaces and new-lines, and prints it to the console.
<
rn: nrows, rh: height of rows
cn: ncols, cw: width of columns
Line 3,571 ⟶ 3,980:
end
println("\n$t\n")
end</
Using these is simple, only provide the data, and prt it.
<
Tbl.CH[1,:] = string.(0:15,base=16) # Column headers
Tbl.RH[:,2] = string.(0:15,base=16) # Row headers
Line 3,579 ⟶ 3,988:
Tbl.T[i>>4+1,i&15+1,1:2]=["$i",i∈(0,7,8,9,10,13,27,155) ? "" : "$(Char(i))"]
end
prt(Tbl) # format and print table on console</
=={{header|K}}==
{{works with|ngn/k}}
<syntaxhighlight lang=K>`0:"\n"/" "/'+6 16#{-6$($x),-2$`c$x}'32+!96
32 48 0 64 @ 80 P 96 ` 112 p
33 ! 49 1 65 A 81 Q 97 a 113 q
34 " 50 2 66 B 82 R 98 b 114 r
35 # 51 3 67 C 83 S 99 c 115 s
36 $ 52 4 68 D 84 T 100 d 116 t
37 % 53 5 69 E 85 U 101 e 117 u
38 & 54 6 70 F 86 V 102 f 118 v
39 ' 55 7 71 G 87 W 103 g 119 w
40 ( 56 8 72 H 88 X 104 h 120 x
41 ) 57 9 73 I 89 Y 105 i 121 y
42 * 58 : 74 J 90 Z 106 j 122 z
43 + 59 ; 75 K 91 [ 107 k 123 {
44 , 60 < 76 L 92 \ 108 l 124 |
45 - 61 = 77 M 93 ] 109 m 125 }
46 . 62 > 78 N 94 ^ 110 n 126 ~
47 / 63 ? 79 O 95 _ 111 o 127</syntaxhighlight>
=={{header|Kotlin}}==
{{trans|Go}}
<
fun main(args: Array<String>) {
Line 3,597 ⟶ 4,026:
println()
}
}</
{{output}}
Line 3,616 ⟶ 4,045:
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del </pre>
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def format
{lambda {:i :c}
{if {< :i 100}
then {span {@ style="color:white;"}.}:i : :c
else :i : :c}}}
-> format
{S.map
{lambda {:i}
{div}
{S.map {lambda {:i}
{if {= :i 32} then {format :i {span {@ style="color:#fff;"}.}}
else {if {= :i 123} then {format :i left brace}
else {if {= :i 125} then {format :i right brace}
else {if {= :i 127} then {format :i del}
else {format :i {code2char :i}}}}}}}
{S.serie {+ 32 :i} 127 16}}}
{S.serie 0 15}}
32 : 48 : 0 64 : @ 80 : P 96 : ` 112 : p
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r
35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s
36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t
37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u
38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v
39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w
40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x
41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y
42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z
43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : left brace
44 : , 60 : < 76 : L 92 : \ 108 : l 124 : |
45 : - 61 : = 77 : M 93 : ] 109 : m 125 : right brace
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : del
</syntaxhighlight>
=={{header|Lang}}==
<syntaxhighlight lang="lang">
$i
repeat($[i], 16) {
$j $= $i + 32
while($j < 128) {
if($j == 32) {
$val = SPC
}elif($j == 127) {
$val = DEL
}else {
$val = fn.char($j)
}
fn.printf(%4d : %-3s, $j, $val)
$j += 16
}
fn.println()
}
</syntaxhighlight>
{{out}}
<pre>
32 : SPC 48 : 0 64 : @ 80 : P 96 : ` 112 : p
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r
35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s
36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t
37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u
38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v
39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w
40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x
41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y
42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z
43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : {
44 : , 60 : < 76 : L 92 : \ 108 : l 124 : |
45 : - 61 : = 77 : M 93 : ] 109 : m 125 : }
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : DEL
</pre>
=={{header|langur}}==
{{trans|Go}}
<syntaxhighlight lang="langur">for .i of 16 {
for .j = 31 + .i ; .j < 128 ; .j += 16 {
val .L =
write $"\{.j:3
}
writeln()
}</
{{out}}
Line 3,648 ⟶ 4,161:
=={{header|Locomotive Basic}}==
<
20 for x=1 to 6
30 for y=1 to 16
Line 3,656 ⟶ 4,169:
70 print " ";chr$(n);
80 next
90 next</
{{out}}
Line 3,678 ⟶ 4,191:
=={{header|Lua}}==
{{trans|Go}}
<
-- map of character values to desired representation
local chars = setmetatable({[32] = "Spc", [127] = "Del"}, {__index = function(_, k) return string.char(k) end})
Line 3,694 ⟶ 4,207:
end
io.write"\n"
end</
{{out}}
Line 3,715 ⟶ 4,228:
=={{header|M2000 Interpreter}}==
Addition: Show all Ascii from 0, using 0x2400 to 0x2420 unicode symbols.
<syntaxhighlight lang="m2000 interpreter">
Function ProduceAscii$ {
Document Ascii$="\"
DelUnicode$=ChrCode$(0x2421)
j=
Print Ascii$;
For i=0 to 15
Line 3,725 ⟶ 4,240:
Ascii$=Hex$(i, .5)
Next
For i=
If pos>16 then
Ascii$={
}+Hex$(j, .5)
Print : Print Hex$(j, .5);: j++
End if
Print Chrcode$(i+0x2400);
Ascii$=Chrcode$(i+0x2400)
Next
For i=33 to 126
If pos>16 then
Ascii$={
Line 3,739 ⟶ 4,263:
}
Clipboard ProduceAscii$()
</syntaxhighlight>
{{out}}
<pre>
\0123456789ABCDEF
0␀␁␂␃␄␅␆␇␈␉␊␋␌␍␎␏
1␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟
2␠!"#$%&'()*+,-./
30123456789:;<=>?
4@ABCDEFGHIJKLMNO
Line 3,749 ⟶ 4,275:
6`abcdefghijklmno
7pqrstuvwxyz{|}~␡
</pre>
=={{header|MACRO-11}}==
<syntaxhighlight lang="macro11"> .TITLE ASCTAB
.MCALL .PRINT,.EXIT
ASCTAB::MOV #40,R5
MOV #20,R4
1$: MOV #NBUF,R1
MOV R5,R2
2$: MOV #-1,R3
3$: INC R3
SUB #12,R2
BCC 3$
ADD #72,R2
MOVB R2,-(R1)
MOV R3,R2
BNE 2$
CMP R1,#NUM
BEQ 4$
MOVB #40,-(R1)
4$: .PRINT #NUM
CMP #40,R5
BEQ 5$
CMP #177,R5
BEQ 6$
MOVB R5,CHR
.PRINT #CHR
BR 7$
5$: .PRINT #SPC
BR 7$
6$: .PRINT #DEL
7$: ADD #20,R5
CMP R5,#200
BLT 1$
SUB #137,R5
.PRINT #NL
DEC R4
BNE 1$
.EXIT
NUM: .ASCII / /
NBUF: .ASCII /: /<200>
CHR: .ASCII /. /<200>
SPC: .ASCII /SPC /<200>
DEL: .ASCII /DEL /<200>
NL: .ASCIZ //
.END ASCTAB</syntaxhighlight>
{{out}}
<pre> 32: SPC 48: 0 64: @ 80: P 96: ` 112: p
33: ! 49: 1 65: A 81: Q 97: a 113: q
34: " 50: 2 66: B 82: R 98: b 114: r
35: # 51: 3 67: C 83: S 99: c 115: s
36: $ 52: 4 68: D 84: T 100: d 116: t
37: % 53: 5 69: E 85: U 101: e 117: u
38: & 54: 6 70: F 86: V 102: f 118: v
39: ' 55: 7 71: G 87: W 103: g 119: w
40: ( 56: 8 72: H 88: X 104: h 120: x
41: ) 57: 9 73: I 89: Y 105: i 121: y
42: * 58: : 74: J 90: Z 106: j 122: z
43: + 59: ; 75: K 91: [ 107: k 123: {
44: , 60: < 76: L 92: \ 108: l 124: |
45: - 61: = 77: M 93: ] 109: m 125: }
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: DEL</pre>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
{{out}}
<pre>32: Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 3,771 ⟶ 4,360:
47: / 63: ? 79: O 95: _ 111: o 127: Del </pre>
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [Stdout table]
table :: [char]
table = lay [concat [item n | n<-[row, (row+16)..127]] | row<-[32..47]]
item :: num->[char]
item n = num ++ " : " ++ desc
where num = reverse (take 3 (reverse (shownum n) ++ repeat ' '))
desc = "Spc ", if n = 32
= "Del ", if n = 127
= decode n : " ", otherwise</syntaxhighlight>
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r
35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s
36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t
37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u
38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v
39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w
40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x
41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y
42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z
43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : {
44 : , 60 : < 76 : L 92 : \ 108 : l 124 : |
45 : - 61 : = 77 : M 93 : ] 109 : m 125 : }
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del</pre>
=={{header|MiniScript}}==
<
// Note changing the values of startChar and endChar will print
// a flexible table in that range
Line 3,806 ⟶ 4,425:
end if
end for
if line then print line // final check for odd incomplete line output</
{{out}}
<pre>
Line 3,826 ⟶ 4,445:
122 : z 123 : { 124 : | 125 : } 126 : ~ 127 : DEL
</pre>
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE AsciiTable;
FROM InOut IMPORT Write, WriteCard, WriteString, WriteLn;
VAR row, col: CARDINAL;
PROCEDURE WriteItem(n: CARDINAL);
BEGIN
WriteCard(n, 3);
WriteString(": ");
CASE n OF
32: WriteString("Spc ")
| 127: WriteString("Del ")
ELSE
Write(CHR(n));
WriteString(" ")
END
END WriteItem;
BEGIN
FOR row := 32 TO 47 DO
FOR col := row TO 127 BY 16 DO
WriteItem(col)
END;
WriteLn
END
END AsciiTable.</syntaxhighlight>
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
33: ! 49: 1 65: A 81: Q 97: a 113: q
34: " 50: 2 66: B 82: R 98: b 114: r
35: # 51: 3 67: C 83: S 99: c 115: s
36: $ 52: 4 68: D 84: T 100: d 116: t
37: % 53: 5 69: E 85: U 101: e 117: u
38: & 54: 6 70: F 86: V 102: f 118: v
39: ' 55: 7 71: G 87: W 103: g 119: w
40: ( 56: 8 72: H 88: X 104: h 120: x
41: ) 57: 9 73: I 89: Y 105: i 121: y
42: * 58: : 74: J 90: Z 106: j 122: z
43: + 59: ; 75: K 91: [ 107: k 123: {
44: , 60: < 76: L 92: \ 108: l 124: |
45: - 61: = 77: M 93: ] 109: m 125: }
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: Del</pre>
=={{header|Nanoquery}}==
{{trans|C}}
<
for i in range(0, 15)
for j in range(32 + i, 127, 16)
Line 3,842 ⟶ 4,506:
end
println
end</
{{out}}
Line 3,863 ⟶ 4,527:
=={{header|Nim}}==
<
for i in 0..15:
Line 3,872 ⟶ 4,536:
else: $chr(j)
write(stdout, fmt"{j:3d} : {k:<6s}")
write(stdout, "\n")</
{{out}}
Line 3,896 ⟶ 4,560:
=={{header|Objeck}}==
{{trans|Java}}
<
function : Main(args : String[]) ~ Nil {
for(i := 32; i <= 127 ; i += 1;) {
Line 3,912 ⟶ 4,576:
};
}
}</
{{output}}
Line 3,932 ⟶ 4,596:
116: t 117: u 118: v 119: w 120: x 121: y
122: z 123: { 124: | 125: } 126: ~ 127: Del
</pre>
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let show_char i =
Printf.printf "%5u: %s" i (match i with 32 -> "SPC" | 127 -> "DEL"
| _ -> Printf.sprintf " %c " (char_of_int i))
let () =
for i = 32 to 47 do
for j = 0 to 5 do show_char (j lsl 4 + i) done |> print_newline
done</syntaxhighlight>
{{out}}
<pre>
32: SPC 48: 0 64: @ 80: P 96: ` 112: p
33: ! 49: 1 65: A 81: Q 97: a 113: q
34: " 50: 2 66: B 82: R 98: b 114: r
35: # 51: 3 67: C 83: S 99: c 115: s
36: $ 52: 4 68: D 84: T 100: d 116: t
37: % 53: 5 69: E 85: U 101: e 117: u
38: & 54: 6 70: F 86: V 102: f 118: v
39: ' 55: 7 71: G 87: W 103: g 119: w
40: ( 56: 8 72: H 88: X 104: h 120: x
41: ) 57: 9 73: I 89: Y 105: i 121: y
42: * 58: : 74: J 90: Z 106: j 122: z
43: + 59: ; 75: K 91: [ 107: k 123: {
44: , 60: < 76: L 92: \ 108: l 124: |
45: - 61: = 77: M 93: ] 109: m 125: }
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: DEL
</pre>
=={{header|OxygenBasic}}==
<syntaxhighlight lang="text">
uses console
int i,j
Line 3,953 ⟶ 4,646:
next
pause
</syntaxhighlight>
=={{header|Perl}}==
Output in the same style as Raku.
{{trans|Raku}}
<
binmode STDOUT, ':utf8';
Line 3,977 ⟶ 4,670:
}
}
print qq[|}\n];</
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 3,989 ⟶ 4,682:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ascii</span><span style="color: #0000FF;">,</span><span style="color: #000000;">16</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"\x7F"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"del"</span><span style="color: #0000FF;">))</span>
<!--</
{{out}}
<pre> 32 (#20): 48 (#30): 0 64 (#40): @ 80 (#50): P 96 (#60): ` 112 (#70): p
Line 4,010 ⟶ 4,703:
=={{header|PHP}}==
<
echo '+' . str_repeat('----------+', 6), PHP_EOL;
Line 4,025 ⟶ 4,718:
echo '|', PHP_EOL;
}
echo '+' . str_repeat('----------+', 6), PHP_EOL;</
{{out}}
Line 4,048 ⟶ 4,741:
=={{header|PL/M}}==
<syntaxhighlight lang="pli">
100H: /* SHOW AN ASCII TABLE FROM 32 TO 127 */
/* CP/M BDOS SYSTEM CALL */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
Line 4,064 ⟶ 4,758:
END PR$BYTE;
/* ASCII TABLE */
DECLARE ( A, C ) BYTE;
DO C = 32 TO
CALL PR$
ELSE
CALL PR$CHAR( '
CALL PR$CHAR(
CALL PR$CHAR( ' ' );
END;
END;
END;
EOF
</syntaxhighlight>
{{out}}
<pre>
032: SPC
</pre>
=={{header|Prolog}}==
<
forall(between(32, 47, N), row(N)).
Line 4,114 ⟶ 4,811:
ascii(32) :- write(' Spc '), !.
ascii(127) :- write(' Del '), !.
ascii(A) :- char_code(D,A), format(' ~w ', D).</
{{out}}
<pre>
Line 4,140 ⟶ 4,837:
=={{header|PureBasic}}==
<
Define r.i, c.i
For r=0 To 15
Line 4,158 ⟶ 4,855:
Next
Input()
EndIf</
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 4,180 ⟶ 4,877:
===Imperative===
{{trans|Go}}
<
for i in range(16):
for j in range(32+i, 127+1, 16):
Line 4,191 ⟶ 4,888:
print("%3d : %-3s" % (j,k), end="")
print()
</syntaxhighlight>
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 4,212 ⟶ 4,909:
===HTML===
After Raku, but creating an HTML table:
<
from html import escape
Line 4,227 ⟶ 4,924:
print(" </tr><tr>")
print(f' <td style="center">{n}<br>0x{n:02x}<br><big><b title="{escape(name(pp(n)))}">{escape(pp(n))}</b></big></td>')
print(""" </tr>\n</table>""")</
{{out}}
Line 4,373 ⟶ 5,070:
Composed from generic abstractions:
<
from functools import reduce
Line 4,480 ⟶ 5,177:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 4,500 ⟶ 5,197:
===List Comprehensions===
<
# One-liner
# print('\n'.join([''.join(["%3d : %-3s" % (a, 'Spc' if a == 32 else 'Del' if a == 127 else chr(a)) for a in lst]) for lst in [[i+c*16 for c in range(6)] for i in range(32, 47+1)]])
Line 4,516 ⟶ 5,213:
# Joining columns into rows and printing rows one in a separate line
print('\n'.join([''.join(row) for row in rows_as_strings]))</
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 4,536 ⟶ 5,233:
=={{header|QB64}}==
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">DIM s AS STRING
FOR i% = 32 TO 47
Line 4,551 ⟶ 5,250:
NEXT j%
PRINT
NEXT i%</
{{out}}
<pre>
Line 4,573 ⟶ 5,272:
=={{header|Quackery}}==
<
[ dup 32 = iff
[ drop say 'spc' ] done
Line 4,591 ⟶ 5,290:
echotable
</syntaxhighlight>
{{out}}
<pre>
Line 4,613 ⟶ 5,312:
=={{header|R}}==
<
rawToChar(as.raw(n))
}
Line 4,629 ⟶ 5,328:
idx <- idx + 6
cat("\n")
}</
{{out}}
<pre> 32 : Spc 33 : ! 34 : " 35 : # 36 : $ 37 : %
Line 4,650 ⟶ 5,349:
=={{header|Racket}}==
<
(for ([i (in-range 16)])
Line 4,661 ⟶ 5,360:
[127 "DEL"]
[_ (integer->char n)]) #:min-width 5)))
(newline))</
{{out}}
Line 4,686 ⟶ 5,385:
Alternately, and perhaps more usefully, output as a wiki-table rather than ASCII art. Hover mouse over the glyph to get the name.
<syntaxhighlight lang="raku"
when * < 33 { (0x2400 + $_).chr } # display symbol names for invisible glyphs
when 127 { '␡' }
Line 4,701 ⟶ 5,400:
}
say '|}';</
{{out}}
{|class="wikitable" style="text-align:center;background-color:hsl(39, 90%, 95%)"
Line 4,843 ⟶ 5,542:
=={{header|Red}}==
<
repeat i 16 [
Line 4,855 ⟶ 5,554:
]
prin newline
]</
{{out}}
<pre>
Line 4,891 ⟶ 5,590:
:::* the suppression of displaying particular glyphs by REXX that are preempted by the OS.
:::* adding homage to the adage of: ''anything worth doing is worth doing well''.
<
parse upper version !ver . /*some REXXes can't display '1b'x glyph*/
!pcRexx= 'REXX/PERSONAL'==!ver | "REXX/PC"==!ver /*is this PC/REXX or REXX/Personal? */
Line 4,932 ⟶ 5,631:
/*──────────────────────────────────────────────────────────────────────────────────────*/
xhdr: say; _= hdr; sep= b; do k=0 for 16; _=_||b d2x(k)b; end; say _; say; return
grid: arg $1,$2,$3,$4; _=hdr; do 16; _=_ || $1 || $4; $1= $2; end; say _ || $3; return</
{{out|output|text= showing a ''horizontal'' formatted grid (table):}}
Line 4,987 ⟶ 5,686:
=={{header|Ring}}==
<
# Project : Show Ascii table
Line 5,034 ⟶ 5,733:
}
exec()
}</
Output:
Line 5,040 ⟶ 5,739:
=={{header|Ruby}}==
<
k = case ord
when 32 then "␠"
Line 5,049 ⟶ 5,748:
end
chars.each_slice(chars.size/6).to_a.transpose.each{|s| puts s.join(" ")}</
{{out}}
<pre>32 : ␠ 48 : 0 64 : @ 80 : P 96 : ` 112: p
Line 5,071 ⟶ 5,770:
=={{header|Rust}}==
{{trans|Go}}
<
for i in 0u8..16 {
for j in ((32+i)..128).step_by(16) {
Line 5,083 ⟶ 5,782:
println!();
}
}</
{{out}}
Line 5,106 ⟶ 5,805:
{{Out}}Best seen in running your browser either by [https://scalafiddle.io/sf/ouiyD9x/0 ScalaFiddle (your local ES aka JavaScript execution, non JVM)] or [https://scastie.scala-lang.org/OD7rBCSMQgKSyKKcGB24cg Scastie (remote JVM)].
{{works with|Scala|2.13}}
<
val (strtCharVal, lastCharVal, nColumns) = (' '.toByte, '\u007F'.toByte, 6)
require(nColumns % 2 == 0, "Number of columns must be even.")
Line 5,130 ⟶ 5,829:
.map(_.map(byte => f"$byte%3d : ${k(byte)}"))
.foreach(line => println(line.mkString(" ")))
}</
=={{header|Seed7}}==
<
const proc: main is func
Line 5,153 ⟶ 5,852:
writeln;
end for;
end func;</
{{out}}
Line 5,178 ⟶ 5,877:
{{works with|HomeSpun}}
{{works with|OpenSpin}}
<
_clkmode = xtal1+pll16x
_clkfreq = 80_000_000
Line 5,207 ⟶ 5,906:
waitcnt(_clkfreq + cnt)
ser.stop</
{{out}}
<pre> 32: SPC 48: 0 64: @ 80: P 96: ` 112: p
Line 5,227 ⟶ 5,926:
=={{header|Standard ML}}==
<syntaxhighlight lang="text">fun Table n 127 = " 127: 'DEL'\n"
| Table 0 x = "\n" ^ (Table 10 x)
| Table n x = (StringCvt.padLeft #" " 4 (Int.toString x)) ^ ": '" ^ (str (chr x)) ^ "' " ^ ( Table (n-1) (x+1)) ;
print (Table 10 32) ;</
32: ' ' 33: '!' 34: '"' 35: '#' 36: '$' 37: '%' 38: '&' 39: ''' 40: '(' 41: ')'
42: '*' 43: '+' 44: ',' 45: '-' 46: '.' 47: '/' 48: '0' 49: '1' 50: '2' 51: '3'
Line 5,245 ⟶ 5,944:
=={{header|Tcl}}==
{{trans|AWK}}
<syntaxhighlight lang="tcl">
for {set i 0} {$i < 16} {incr i} {
for {set j $i} {$j < 128} {incr j 16} {
Line 5,257 ⟶ 5,956:
puts ""
}
</syntaxhighlight>
{{out}}
<pre>
Line 5,277 ⟶ 5,976:
47: / 63: ? 79: O 95: _ 111: o 127: DEL
</pre>
=={{header|TXR}}==
<syntaxhighlight lang="txrlisp">(let ((spcdel (relate " \x7f" #("Spc" "Del"))))
(each ((r 32..48))
(each ((c (take 6 (range r : 16))))
(put-string (pic "###: <<<" c [spcdel (chr-num c)])))
(put-line)))</syntaxhighlight>
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
33: ! 49: 1 65: A 81: Q 97: a 113: q
34: " 50: 2 66: B 82: R 98: b 114: r
35: # 51: 3 67: C 83: S 99: c 115: s
36: $ 52: 4 68: D 84: T 100: d 116: t
37: % 53: 5 69: E 85: U 101: e 117: u
38: & 54: 6 70: F 86: V 102: f 118: v
39: ' 55: 7 71: G 87: W 103: g 119: w
40: ( 56: 8 72: H 88: X 104: h 120: x
41: ) 57: 9 73: I 89: Y 105: i 121: y
42: * 58: : 74: J 90: Z 106: j 122: z
43: + 59: ; 75: K 91: [ 107: k 123: {
44: , 60: < 76: L 92: \ 108: l 124: |
45: - 61: = 77: M 93: ] 109: m 125: }
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: Del</pre>
=={{header|VBA}}==
<syntaxhighlight lang="vb">
Public Sub ascii()
Dim s As String, i As Integer, j As Integer
Line 5,293 ⟶ 6,019:
Debug.Print vbCrLf
Next i
End Sub</
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 5,315 ⟶ 6,041:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<
Imports System.Linq.Enumerable
Line 5,328 ⟶ 6,054:
Loop While start + 16 * 5 < 128
End Sub
End Module</
{{out}}
<pre>32 : Sp 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 5,347 ⟶ 6,073:
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del </pre>
=={{header|V (Vlang)}}==
{{trans|go}}
<syntaxhighlight lang="v (vlang)">fn main() {
for i in 0..16{
for j := 32 + i; j < 128; j += 16 {
Line 5,366 ⟶ 6,092:
println('')
}
}</
{{out}}
Line 5,386 ⟶ 6,112:
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del </pre>
=={{header|VTL-2}}==
<syntaxhighlight lang="vtl2">10 C=32
20 L=16
30 #=C>100*50
40 $=32
50 ?=C
60 ?=": ";
70 #=C=32*120
80 #=C=127*140
90 $=C
100 ?=" ";
110 #=150
120 ?="Spc ";
130 #=150
140 ?="Del ";
150 C=C+16
160 #=C<128*30
170 C=C-95
180 L=L-1
190 ?=""
200 #=L=0=0*30</syntaxhighlight>
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
33: ! 49: 1 65: A 81: Q 97: a 113: q
34: " 50: 2 66: B 82: R 98: b 114: r
35: # 51: 3 67: C 83: S 99: c 115: s
36: $ 52: 4 68: D 84: T 100: d 116: t
37: % 53: 5 69: E 85: U 101: e 117: u
38: & 54: 6 70: F 86: V 102: f 118: v
39: ' 55: 7 71: G 87: W 103: g 119: w
40: ( 56: 8 72: H 88: X 104: h 120: x
41: ) 57: 9 73: I 89: Y 105: i 121: y
42: * 58: : 74: J 90: Z 106: j 122: z
43: + 59: ; 75: K 91: [ 107: k 123: {
44: , 60: < 76: L 92: \ 108: l 124: |
45: - 61: = 77: M 93: ] 109: m 125: }
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: Del</pre>
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-fmt}}
<
for (i in 0...16) {
Line 5,405 ⟶ 6,169:
}
System.print()
}</
{{out}}
Line 5,428 ⟶ 6,192:
=={{header|XPL0}}==
<
[SetHexDigits(2);
Text(0, " ");
Line 5,440 ⟶ 6,204:
CrLf(0);
];
]</
{{out}}
Line 5,462 ⟶ 6,226:
0F / ? O _ o
</pre>
=={{header|Z80 Assembly}}==
{{works with|CP/M 3.1|YAZE-AG-2.51.2 Z80 emulator}}
{{works with|ZSM4 macro assembler|YAZE-AG-2.51.2 Z80 emulator}}
Use the /S8 switch on the ZSM4 assembler for 8 significant characters for labels and names
<syntaxhighlight lang="z80">
;
; Print ASCII table using Z80 assembly language
;
; Runs under CP/M 3.1 on YAZE-AG-2.51.2 Z80 emulator
; Assembled with zsm4 on same emulator/OS, uses macro capabilities of said assembler
; Created with vim under Windows
;
; Thanks to https://wikiti.brandonw.net for the idea for the conversion routine hl -> decimal ASCII
;
; 2023-04-04 Xorph
;
;
; Useful definitions
;
bdos equ 05h ; Call to CP/M BDOS function
strdel equ 6eh ; Set string delimiter
wrtstr equ 09h ; Write string to console
numrows equ 16d ; Number of rows for output
numcols equ 6d ; Number of columns for output
nul equ 00h ; ASCII control characters
esc equ 1bh
cr equ 0dh
lf equ 0ah
cnull equ '0' ; ASCII character constants
spc equ 20h
del equ 7fh
;
; Macros for BDOS calls
;
setdel macro char ; Set string delimiter to char
ld c,strdel
ld e,char
call bdos
endm
print macro msg ; Output string to console
ld c,wrtstr
ld de,msg
call bdos
endm
newline macro ; Print newline
ld c,wrtstr
ld de,crlf
call bdos
endm
pushall macro ; Save all registers to stack
push af
push bc
push de
push hl
push ix
push iy
endm
popall macro ; Recall all registers from stack
pop iy
pop ix
pop hl
pop de
pop bc
pop af
endm
;
; =====================
; Start of main program
; =====================
;
cseg
asciitab:
setdel nul ; Set string terminator to nul ('\0') - '$' is default in CP/M
ld a,spc ; First ASCII code to print
loop:
ld (char),a ; Put ASCII code in output placeholder
ld h,0 ; Register pair hl is used for printing the number, register h remains 0
ld l,a ; Put ASCII code in hl for decimal conversion
ld ix,buffer
call dispHL ; Create decimal representation
ld d,3d ; Pad decimal representation to 3 places with leading blanks
ld e,' ' ; Registers d and e are modified in macro, so assign each time
ld hl,buffer
ld bc,format
call padstrl
print format ; Print the whole thing
print colon
chkspc:
ld a,(char) ; Load again, register a was lost during BDOS calls
cp spc ; Check if Spc
jr nz,chkdel ; If not, check if Del
print txtspc ; If yes, print the text for Spc
jr nextcol ; ...and skip to the next column
chkdel:
ld a,(char) ; Load again, register a was lost during BDOS calls
cp del ; Check if Del
jr nz,printc ; If not, print normal char
print txtdel ; If yes, print the text for Del
jr nextcol ; ...and skip to the next column
printc:
print char ; Normal char
nextcol:
ld a,(curcol) ; Increase output column
inc a
cp numcols ; If last column, go to next row
jr z,nextrow
ld (curcol),a ; Save column counter
ld a,(char) ; Increase ASCII code by the number of rows for next column in same row
add a,numrows
jr loop ; Next code
nextrow:
newline ; Display next row
xor a ; Set column counter back to 0
ld (curcol),a
ld a,(currow) ; Increase row counter
inc a
cp numrows ; When last row has been finished, we are done
jr z,exitprg
ld (currow),a ; Save row counter
ld a,(char) ; Set ASCII code back to starting code of next row
sub a,numrows * (numcols - 1d) - 1d
jp loop ; Use jp instead of jr because of jump distance!
exitprg:
newline
ret ; Return to CP/M
;
; ===================
; End of main program
; ===================
;
;
; Helper routines - notice that the Z80 does not have a divide instruction
; Notice further that CP/M does not have any support for pretty-printing
; formatted numbers and stuff like that. So we have to do all this by hand...
;
;
; Converts the value (unsigned int) in register hl to its decimal representation
; Register ix has memory address of target for converted value
; String is terminated with nul character (\0)
;
dispHL:
pushall
ld b,1 ; Flag for leading '0'
irp x,<-10000,-1000,-100,-10,-1>
ld de,x ; Subtract powers of 10 and determine digit
call calcdig
endm
ld a,nul ; Terminate result string with nul
ld (ix+0),a
popall
ret ; End of conversion routine
calcdig:
ld a,cnull-1 ; Determine the digit character
incrdig:
inc a ; Start with '0'
add hl,de ; As long as subtraction is possible, increment digit character
jr c,incrdig
sbc hl,de ; If negative, undo last subtraction and continue with remainder
cp cnull ; Check for leading '0', these are ignored
jr nz,adddig
bit 0,b ; Use bit instruction for check if flag set, register a contains digit
ret nz ; If '0' found and flag set, it is a leading '0' and we return
adddig:
ld b,0 ; Reset flag for leading '0', we are now outputting digits
ld (ix+0),a ; Store character in memory and set ix to next location
inc ix
ret ; End of conversion helper routine
;
; Formats a string to the specified minimum width with the specified filler character
; Register hl has memory address of nul-terminated string
; Register bc has memory address of target for padded string
; Register d has width
; Register e has filler character/byte
; Padding is on the left (function is intended for padding integer numbers)
;
padstrl:
pushall
push hl ; Save address of source for copy later on
ld a,d ; Check if width is 0, just copy string if so
cp 0
jr z,copysrc
ld a,nul ; Search for end of string. Each non-nul character decrements d
findnul:
cp (hl)
jr z,nulfound ; Found end of string, d contains number of padding to add
dec d
jr z,copysrc
inc hl
jr findnul ; Repeat with next character
nulfound:
ld a,e ; Store as many padding characters to target as specified in register d
inspad:
ld (bc),a
inc bc ; Move to next memory address and decrease d
dec d
jr nz,inspad
copysrc:
pop hl ; Transfer source to target, bc points to first memory address after padding
movechar:
ld a,(hl)
ld (bc),a
inc hl
inc bc
cp nul ; Check if nul character copied
jr nz,movechar ; If no, repeat with next character
popall
ret ; End of padding routine
;
; ================
; Data definitions
; ================
;
dseg
crlf: defb cr,lf,nul ; Generic newline
buffer: defs 10 ; Buffer for conversion of number to text
format: defs 10 ; Formatted number for output
colon: defz ' : ' ; Separator number/character, nul-terminated
char: defz ' ' ; Placeholder for ASCII character, nul-terminated
txtspc: defz 'Spc ' ; Space character 20h
txtdel: defz 'Del ' ; Del character 7fh
currow: defb 0d ; Current row
curcol: defb 0d ; Current column
</syntaxhighlight>
{{out}}
<pre>
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r
35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s
36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t
37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u
38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v
39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w
40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x
41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y
42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z
43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : {
44 : , 60 : < 76 : L 92 : \ 108 : l 124 : |
45 : - 61 : = 77 : M 93 : ] 109 : m 125 : }
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
</pre>
=={{header|Zig}}==
{{trans|Java}}
<syntaxhighlight lang="zig">const print = @import("std").debug.print;
pub fn main() void {
var i: u8 = 33;
print(" 32: Spc", .{});
while (i < 127) : (i += 1) {
print("{:03}: {c} ", .{ i, i });
if (@mod(i, 6) == 1) {
print("\n", .{});
}
}
print("127: Del", .{});
}</syntaxhighlight>
=={{header|zkl}}==
<
println(" ",[0..width].pump(String,"%4d".fmt));
[30..127].pump("".println,T(Void.Read,width,False), // don't fail on short lines
Line 5,473 ⟶ 6,538:
T("replace"," ","spc"),T("replace","\x7f","del"), "%-4s".fmt)
)
})</
{{out}}
<pre> 0 1 2 3 4 5 6 7 8 9
Line 5,489 ⟶ 6,554:
=={{header|ZX Spectrum Basic}}==
Note in particular entries 94, 96 and 127.
<
20 PRINT AT 0,4+2*x;x
30 PRINT AT x+1,0;10*(3+x)
Line 5,497 ⟶ 6,562:
70 LET t=(x-d)/10
80 PRINT AT t-2,4+2*d;CHR$ x
90 NEXT x</
{{out}}
|