astrorat.com

Some Simple 1802 Assembly Programs

PROGRAM NAME: Walkingbit
DATE: August 2011
BY: Unknown

COMMENT: This short program turn on the most significant LED, delays and then rotates (walks) one LED to the right. Once all eight LEDs are walked through, the program repeats forever.

REGISTERS USED:
R0 Program counter.
R1 Delay counter.
R2 Memory pointer to current bit pattern.
 
0000 E2     START:    SEX R2       ; Set X to point at R2.
0001 F8 17            LDI PATTERN  ; R2 points at RAM location with the PATTERN.
0003 A2               PLO R2
0004 F8 00            LDI 00h
0006 B2               PHI R2
0007 FD 00            SDI 00h      ; Set the DF to 1 for start pattern.
0009 52     WALK:     STR R2       ; Save the current bit pattern.
000A 64               OUT 4        ; Display the pattern.
000B 22               DEC R2       ; Undo the increment from the OUT command.
000C F8 08  DELAY:    LDI 08h      ; Set delay in R1 to 8 x 256 = 2048.
000E B1               PHI R1
000F 21     DLOOP:    DEC R1       ; Decrement delay count in R1.
0010 91               GHI R1       ; If not done with delay do another round.
0011 3A 0F            BNZ DLOOP
0013 02               LDN R2       ; Rotate the pattern one bit to the right.
0014 76               RSHR
0015 30 09            BR WALK      ; Do it all again forever.
0017 00     PATTERN:  DB 0         ; RAM location of the pattern byte.
PROGRAM NAME: Byteguess
DATE: September 1976
BY: Joseph Weisbecker
UPDATED BY: Dave Runkle (for the Retro Elf Version)

COMMENT: This program "think" of a byte, which you must guess in no more than seven tries. When first run, AA (10101010) is displayed. Enter a guess in to the eight toggle switches and cycle the EF4 switch.  If 00 (00000000) is displayed you win. If 01 (00000001) is displayed you are low. If 80 (10000000) is displayed you are high. After sever tries the Q LED is turned on and the secret byte is displayed.
 
REGISTERS USED:
R0 Program counter.
R3 Memory pointer used by display to store data.
R4.0 Number of tries.
RA.0 New secret byte for next game.
RB.0 Current secret byte.

0000 8A     START:    GLO RA            ; Setup secret byte in RB.0.
0001 AB               PLO RB
0002 F8 00            LDI HIGH DISPLAY  ; Set R3 as memory pointer used by
0004 B3               PHI R3            ; the display port.
0005 F8 32            LDI LOW DISPLAY
0007 A3               PLO R3
0008 F8 AA            LDI 0AAh          ; Display AA.
000A 53               STR R3
000B E3               SEX R3            ; Set X to new R3 display pointer.

000C F8 07            LDI 07h           ; Setup the number of tries = 7 in
000E A4               PLO R4            ; R3.0.
000F 64               OUT 4             ; Display "AA" pattern for start.
0010 23               DEC R3            ; Fix memory pointer after OUT.
0011 2A     SECRET:   DEC RA            ; Wait for EF4 press. While looping,
0012 3F 11            BN4 SECRET        ; decrement new secret byte.
0014 37 14            B4 $              ; Wait for EF4 release.
0016 6C               INP 4             ; Get user guess. Put in to D.
0017 8B               GLO RB            ; Compare guess (D) to secret (RB.0).
0018 F5               SD
0019 33 1F            BGE TEST          ; Branch if guess >= secret.
001B F8 01            LDI 01h           ; guess<secret so display 01h.
001D 30 27            BR SHOW
001F 3A 25  TEST:     BNZ OVER          ; Brach if guess > secret.
0021 53     DONE:     STR R3            ; Display.
0022 64               OUT 4
0023 30 23            BR $              ; Stop.
0025 F8 80  OVER:     LDI 80h           ; Guess > secret so display 80h.
0027 53     SHOW:     STR R3            ; Show status.
0028 64               OUT 4
0029 23               DEC R3            ; Fix memory pointer after OUT.
002A 24               DEC R4            ; Decrement tries counter.
002B 84               GLO R4            ; If not out of tries, guess again.
002C 3A 11            BNZ SECURIT
002E 8B               GLO RB            ; Out of tries, show secret.
002F 7B               SEQ               ; and turn on Q LED.
0030 30 21            BR DONE
0032 00     DISPLAY:  DB 0              ; Location of display data.
PROGRAM NAME: RAMtest
DATE: Unknown  BY: Unknown
COMMENT: Here is a memory test program for the 1802. It is a bit match type test of the 32K RAM. It doesn't check for cross-talk between the memory address lines. This version does check for data line cross-talk. The LED's will display the current memory page being tested. If there is an error detected the "Q" LED will come on and stay on. If an error is detected the address that caused the error is stored at memory location 0002h (high order) and 0003h (low order).  If there is no errors detected the data LED's will count from "00" to "7F" (01111111) and stop.
 
REGISTERS USED:
R0 Program counter.
R2 Points for memory location where RAM being tested pointer is.
R5 Pointer for value for displayed memory address.
RC Pointer to RAM being tested.
RD.0 Current pattern being tested.

0000 30 05  START:    BR TEST    ; Branch to start of RAM test program.
0002 00               DB 0       ; High order test address pointer.
0003 00               DB 0       ; Low order test address pointer.
0004 00               DB 0       ; High order address to display.
0005 90     TEST:     GHI R0     ; Use program counter to set high pointers.
0006 B2               PHI R2
0007 B5               PHI R5
0008 BC               PHI RC
0009 F8 02            LDI 02h    ; R2 points at memory location where pointer is.
000B A2               PLO R2
000C F8 04            LDI 04h    ; R5 points at current display memory.
000E A5               PLO R5
000F F8 42            LDI 42h    ; RC points a RAM test beginning.
0011 AC               PLO RC
0012 F8 01            LDI 01h    ; RD.0 is current test bit pattern.
0014 AD               PLO RD
0015 9C     TESTL:    GHI RC     ; Update display current test page.
0016 55               STR R5
0017 E5               SEX R5

0018 64               OUT 4      ; Display page.
0019 25               DEC R5     ; Fix pointer after display.
001A EC               SEX RC
001B 9C               GHI RC     ; Update current RAM test location
001C 52               STR R2     ; pointed to by R2.
001D 12               INC R2
001E 8C               GLO RC
001F 52               STR R2
0020 22               DEC R2
0021 8D               GLO R
0022 73               STXD
0023 1C               INC RC
0024 F5               SD         ; Test current RAM pattern.
0025 32 2A            BZ NEXT    ; Jump if current RAM passes.
0027 7B               SEQ        ; Error found turn on Q.
0028 30 28            BR $       ; Stop.
002A 8D     NEXT:     GLO RD     ; Change to next text pattern.
002B FE               SHL
002C AD               PLO RD
002D 3A 15            BNZ TESTL  ; Loop if still more test patterns.
002F 5C               STR RC
0030 F8 01            LDI 01h    ; Reset test bit pattern.
0032 AD               PLO RD
0033 1C               INC RC     ; Move to next page of RAM.
0034 9C               GHI RC
0035 FD 80            SDI 80h    ; Last page?
0037 3A 15            BNZ TESTL  ; If not do another page.
0039 30 39            BR $       ; Stop.