We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

7 heptits, 49 heptytes

From Esolang
Jump to navigation Jump to search

7 heptits, 49 heptytes is yet another assembly-like programming language designed by PSTF.

While browsing the Esolang Wiki, I noticed that the assembly languages there use binary, ternary, quinary, and decimal systems, but I always felt something was missing—so I created this septenary programming language system, designed for a seven-heptit CPU and 49-heptyte memory.

Terminology

Before getting to know this base-7 programming language, let's go over a few terms first.

  • Heptit: a single base-7 digit.
  • Heptyte: seven base-7 digits.
  • Word: two heptytes.
  • Register: this language is also built around the number seven, so we have seven registers (AX to GX), with GX also known as SP (stack pointer). Besides, we have also a register called IO for I/O.
  • Flags register: we have four flags registers—zero, sign / negative, carry, and overflow.

Code Page

The Code Page were modified from ASCII, yet we have to truncate something because ASCII has 128 characters while a heptyte can only store up to 49 characters.

 0123456
0⎕⌸⍔⍍ !"
1'()*+,-
2.=01234
356ABCDE
4FGHIJKL
5MNOPQRS
6TUVWXYZ

Instruction Set

00. NOP: No operation
01. ADD Rd, Rs1, Rs2: Rd = Rs1 + Rs2
02. SUB Rd, Rs1, Rs2: Rd = Rs1 - Rs2
03. MUL Rd, Rs1, Rs2: Rd = Rs1 × Rs2
04. DIV Rd, Rs1, Rs2: Rd = Rs1 ÷ Rs2
05. MOD Rd, Rs1, Rs2: Rd = Rs1 mod Rs2
06. CMP Rs1, Rs2: Z, R = Rs1 - Rs2
10. ADDI Rd, Rs, #Imm: Rd = Rs + Imm
11. SUBI Rd, Rs, #Imm: Rd = Rs - Imm
12. MULI Rd, Rs, #Imm: Rd = Rs × Imm
13. DIVI Rd, Rs, #Imm: Rd = Rs ÷ Imm
14. MODI Rd, Rs, #Imm: Rd = Rs mod Imm
15. CMPI Rs, #Imm: Z, R = Rs - Imm
16. MOVI Rd, #Imm: Rd = Imm
20. LDR Rd, [addr]: Rd = MEM[addr]
21. STR Rd, [addr]: MEM[addr] = Rd
22. Undefined
23. MOV Rd, Rs: Rd = Rs
24. NEG Rd, Rs: Rd = -Rs
25. SHL Rd, Rs: Rd = 7Rs
26. SHR Rd. Rs: Rd = Rs ÷ 7
30. JMP addr: PC = addr
31. JEQ addr: PC = addr if Z = 1
32. JNE addr: PC = addr if Z = 0
33. JLT addr: PC = addr if N = 1
34. JGT addr: PC = addr if both Z and N are 0
35. JNL addr: PC = addr if N = 0
36. JNG addr: PC = addr if either Z or N is 1
40. OUT Rd: Print Rd as septenary number
41. IPT Rd: Read a septenary number to Rd
42. SAY Rd: Print Rd as a character
43. LSN Rd: Read a character to Rd
44. PRINT addr1, addr2: Unpack and print the characters heptyte by heptyte until two 00s.
45. Undefined
46. Undefined
50. PSH Rd: GX--, [GX] = Rd
51. POP Rd: Rd = [GX], GX++
52. CALL addr: Push PC then set PC to addr
53. RET: POP PC
54 ~ 65: Undefined
66. HALT

Character Storage

Since each heptyte is made up of seven heptits, and a character consists of two heptits, a heptyte can actually hold only three characters. To store a bunch of characters like this, we use a special system. First, the least noticeable heptit is at the lowest position, followed by the high heptit of the first character, then the low heptit of the first character, and so on — basically, it's stored in big-endian order. If you want to store a single character in a register, just load its 2‑heptit code into a heptyte.

Assembler Derivtives

.ORG addr: Set start point to addr
.WORD value: Reserve a heptite and set it to value
.END: End of Program
.HSTRING "BLAHBLAHBLAH": Pack strings into heptytes mentioned above.
                         Case insensitive, all cases are treated as uppercase.

Stack and Initial State

The stack pointer GX initially points to address 48. When pushing onto the stack, GX is decreased first and then the value is written; when popping from the stack, the value is read first and then GX is increased. The stack grows downward, all the way to address 0.

Although in the program you're supposed to describe immediate numbers in septenary, for the sake of normal humans—rather than some 'alien pianists' (who have seven fingers of equal length on each hand)—we'll use decimal here, since no one actually has seven fingers on a hand.

Examples

Store 5! to the address (42)7

; ------------------------------------------------------------
; H7ASM program: Factorial of 5 (heptal)
; Computes R2 = R2 * R1, decrements R1, repeats until R1 == 0
; ------------------------------------------------------------

.ORG 00                 ; start at address 00

START:
    MOVI R1, #5         ; R1 = 5 (counter)
    MOVI R2, #1         ; R2 = 1 (result)

LOOP:
    CMPI R1, #0         ; compare counter with 0
    JEQ DONE            ; if R1 == 0, jump to DONE
    MUL R2, R2, R1      ; R2 = R2 * R1
    SUBI R1, R1, #1     ; R1 = R1 - 1
    JMP LOOP            ; repeat

DONE:
    STR R2, [42]        ; store result at address 42_7
    HLT

.END

Compiled Form:

1610005 1620001 1510000 3106000 0322100 1111001 3002000 2124200 6600000

Program Part: Allocate "HELLO" start from (20)7

.ORG 20
MSG:
    .HSTRING "HELLO"
    .WORD 0          ; null terminator (two heptits: 00 00)

Categories