MPASM 02.20 Released HELLO.ASM 2-20-1999 11:59:24 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ;HELLO.ASM FEB-15-99 00002 ;"Hello World!" demo with 2-for-1 compression on the Scenix Micro 00003 ; by Loren Blaney 00004 ; 00005 ;Assemble with MPASM. 00006 ; 00007 ;The ability of the Scenix processor to read program memory is used to pack 00008 ; two 6-bit characters into a word. Normally the RETLW instruction would 00009 ; be used, but that only takes advantage of 8 of the 12 bits in a word. 00010 ; 00011 INCLUDE "SXDEFS.INC" ;macro definitions for new instructions 00131 LIST 00132 PROCESSOR 16C54 ; "SX18AA" 00339 LIST 1010 0F0F 00340 DATA _FUSE ;configuration bits (TURBO, SYNC, OPTIONX, etc.) 1011 00F0 00341 DATA _FUSEX ; (PINS, CARRYX, BOR40, BANKS, PAGES) 00345 LIST 00000084 00012 DEVICE EQU OSC4MHZ+WATCHDOG 00013 RADIX DEC 00014 ERRORLEVEL -305,-306 ;",F" is the default; page boundaries are ok 00015 LIST ST=OFF 00016 0007 00017 ORG 07h 0007 00018 TEMP RES 1 ;universal temporary scratch location 00019 00020 ;Variables for MSGOUT routine: 0008 00021 MSGPTR RES 2 ;pointer to words in instruction memory 000A 00022 MSG2ND RES 1 ;holds the second of a pair of characters 00023 0000000D 00024 CR EQU 0Dh ;ASCII characters 0000000A 00025 LF EQU 0Ah 00026 00027 TEXT MACRO A,B ;pack two ASCII characters into a 12-bit word 00028 DATA (A-1Ch & 03Fh)<<6 | B-1Ch & 03Fh 00029 ENDM 00030 00031 0000 00032 ORG 0 00033 ;------------------------------------------------------------------------------- 00034 ;Output the character in W to the printer 00035 ; 0000 0004 00036 CHOUT CLRWDT ;reset watchdog timer 0001 0605 00037 BTFSC RA,0 ;loop until not busy (busy = 1) 0002 0A00 00038 GOTO CHOUT 0003 0026 00039 MOVWF RB ;send byte to printer 00040 00041 ; PRINTX ;simulator print command 00042 0004 0425 00043 BCF RA,1 ;set strobe low (active) for at least 0.5us 0005 0525 00044 BSF RA,1 ;set strobe high (inactive) 00045 RETP 0006 000D M DATA 0Dh ;RETP ;RET & write return addr bits 10:9 into PA1:PA0 00046 MPASM 02.20 Released HELLO.ASM 2-20-1999 11:59:24 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00047 ;------------------------------------------------------------------------------- 00048 ;Print the message pointed to by W and MODE. The W register contains the low 8 00049 ; bits of the address, and MODE contains the high 4 bits. Messages can span 00050 ; page boundaries. The W and MODE registers are changed, along with TEMP. 00051 ; 00052 ;Messages are written using ASCII character codes 20h thru 5Fh. The TEXT macro 00053 ; packs two characters into a 12-bit word. Some characters have special meaning: 00054 ; \ = Reserved. (Used to loop back for second character.) 00055 ; ] = String terminator (end of text). 00056 ; ^ = Shift case (toggles upper/lower). 00057 ; _ = New line (CR+LF). 00058 ; 0007 0028 00059 MSGOUT MOVWF MSGPTR ;save pointer to message 00060 MOVMW 0008 0042 M DATA 42h ;MOVMW ;move MODE register to W register 0009 0029 00061 MOVWF MSGPTR+1 ;also clear bit 5 to select uppercase letters 00062 000A 0209 00063 MO10 MOVF MSGPTR+1,W ;move MSGPTR into MODE:W 00064 MOVWM ; copy low 4 bits in W into MODE 000B 0043 M DATA 43h ;MOVWM ;move W register to MODE register 000C 0208 00065 MOVF MSGPTR,W ; copy low 8 bits of MSGPTR into W 00066 IREAD ;move instruction word at (MODE:W) to MODE:W 000D 0041 M DATA 41h ;IREAD ;move instruction at (MODE:W) to MODE:W 00067 000E 002A 00068 MOVWF MSG2ND ;save second character 00069 MOVMW ;copy MODE to W to TEMP 000F 0042 M DATA 42h ;MOVMW ;move MODE register to W register 0010 0027 00070 MOVWF TEMP 0011 036A 00071 RLF MSG2ND ;form first character (6 bits) in TEMP 0012 0367 00072 RLF TEMP ; TEMP <-- MSG2ND 0013 034A 00073 RLF MSG2ND,W 0014 0367 00074 RLF TEMP 00075 0015 02E7 00076 MO20 DECFSZ TEMP ;test for special characters: 0016 0A18 00077 GOTO MO30 00078 RETP ;1 = ] = string terminator 0017 000D M DATA 0Dh ;RETP ;RET & write return addr bits 10:9 into PA1:PA0 00079 0018 02E7 00080 MO30 DECFSZ TEMP 0019 0A1D 00081 GOTO MO40 001A 0C20 00082 MOVLW 20h ;2 = ^ = shift case 001B 01A9 00083 XORWF MSGPTR+1 ;toggle the case-shift flag bit 001C 0A29 00084 GOTO MO60 00085 001D 02E7 00086 MO40 DECFSZ TEMP 001E 0A23 00087 GOTO MO50 001F 0C0D 00088 MOVLW CR ;3 = _ = new line (CR & LF) 0020 0900 00089 CALL CHOUT 0021 0C0A 00090 MOVLW LF 0022 0A28 00091 GOTO MO55 00092 0023 0C1F 00093 MO50 MOVLW 1Fh ;add offset to convert back to ASCII 0024 01E7 00094 ADDWF TEMP MPASM 02.20 Released HELLO.ASM 2-20-1999 11:59:24 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0025 0209 00095 MOVF MSGPTR+1,W ;shift to uppercase if the case-shift bit 0026 0E20 00096 ANDLW 20h ; is set 0027 0107 00097 IORWF TEMP,W 0028 0900 00098 MO55 CALL CHOUT ;output the ASCII character 00099 0029 030A 00100 MO60 RRF MSG2ND,W ;undo the RLF above 002A 006A 00101 CLRF MSG2ND ;zero it for next time thru loop (0 = \) 002B 0E3F 00102 ANDLW 3Fh ;mask off garbage and set Z status 002C 0027 00103 MOVWF TEMP ;get copy into TEMP (w/o changing status) 002D 0743 00104 BTFSS STATUS,Z 002E 0A15 00105 GOTO MO20 ;loop back for second character 00106 002F 03E8 00107 INCFSZ MSGPTR ;loop until terminator is found 0030 0A0A 00108 GOTO MO10 0031 02A9 00109 INCF MSGPTR+1 ;(in case string spans a page boundary) 0032 0A0A 00110 GOTO MO10 00111 00112 ;------------------------------------------------------------------------------- 00113 ;Initialize parallel output port to the printer 00114 ; 0033 0004 00115 INIT CLRWDT ;reset watchdog timer 0034 0C00 00116 MOVLW 00h ;internal instruction clock 0035 0002 00117 OPTION ;(6-bit option register--no RTCC interrupts) 00118 0036 0CFD 00119 MOVLW 0FDh ;PORT A: 0037 0005 00120 TRIS RA ; bit 0 = input (printer busy line) 00121 ; bit 1 = output (printer strobe line) 0038 0525 00122 BSF RA,1 ;set strobe high (inactive) 00123 0039 0C00 00124 MOVLW 00h ;make all port B bits outputs 003A 0006 00125 TRIS RB 00126 RETP 003B 000D M DATA 0Dh ;RETP ;RET & write return addr bits 10:9 into PA1:PA0 00127 00128 ;------------------------------------------------------------------------------- 00129 ;Entry point 00130 ; 003C 0933 00131 START CALL INIT ;initialize parallel output port 00132 00133 LOOP MODE MSG >> 8 ;get pointer to message M LIST 003D 0050 M DATA 50h|(MSG >> 8) ;MODE ;write N into MODE register (N = 0-F) 003E 0C41 00134 MOVLW MSG & 0FFh 003F 0907 00135 CALL MSGOUT ;output message 0040 0A3D 00136 GOTO LOOP ;loop forever 00137 00138 00139 MSG TEXT 'H', '^' ;Hello World! 0041 0B02 M DATA ('H'-1Ch & 03Fh)<<6 | '^'-1Ch & 03Fh 00140 TEXT 'E', 'L' 0042 0A70 M DATA ('E'-1Ch & 03Fh)<<6 | 'L'-1Ch & 03Fh 00141 TEXT 'L', 'O' 0043 0C33 M DATA ('L'-1Ch & 03Fh)<<6 | 'O'-1Ch & 03Fh MPASM 02.20 Released HELLO.ASM 2-20-1999 11:59:24 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00142 TEXT ' ', '^' 0044 0102 M DATA (' '-1Ch & 03Fh)<<6 | '^'-1Ch & 03Fh 00143 TEXT 'W', '^' 0045 0EC2 M DATA ('W'-1Ch & 03Fh)<<6 | '^'-1Ch & 03Fh 00144 TEXT 'O', 'R' 0046 0CF6 M DATA ('O'-1Ch & 03Fh)<<6 | 'R'-1Ch & 03Fh 00145 TEXT 'L', 'D' 0047 0C28 M DATA ('L'-1Ch & 03Fh)<<6 | 'D'-1Ch & 03Fh 00146 TEXT '!', '_' 0048 0143 M DATA ('!'-1Ch & 03Fh)<<6 | '_'-1Ch & 03Fh 00147 TEXT ']', 0 0049 0064 M DATA (']'-1Ch & 03Fh)<<6 | 0-1Ch & 03Fh 00148 00149 01FF 00150 ORG 01FFh ;reset vector 01FF 0A3C 00151 GOTO START 00152 00153 END MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXX------ ---------------- ---------------- ---------------- 01C0 : ---------------- ---------------- ---------------- ---------------X 1000 : ---------------- XX-------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 75 Program Memory Words Free: 437 Errors : 0 Warnings : 0 reported, 3 suppressed Messages : 0 reported, 10 suppressed