MBedder, терминатор (18.07.2012 23:16 - 22.07.2012 03:04, просмотров: 156) ответил Bill на Маленький пример
1:1 с системой команд/адресации dsPIC/PIC24, поправил только имена регистров, синтаксис использования локальных меток и двухадресных команд SL/INC, и мнемоники условных переходов
;+
; ** GETCC - READ IN A CHARACTER CONSTANT
;
; READ A CHARACTER CONSTANT INTO VAL1. THIS ROUTINE IS SENSITIVE TO
; THE ORDER OF CHARACTERS IN A WORD (IN THE PDP-11, UNLIKE THE VAST
; MAJORITY OF MACHINES, THIS IS RIGHT TO LEFT).
;
; A DIAGNOSTIC IS GENERATED IF THE CHARACTER CONSTANT ENDS SUDDENLY,
; OR CONTAINS TOO MANY (>2) CHARACTERS.
;
; USES:
; R0, R1, R2
;-
;-------------------------------------------------------------------------------------------------------------
; DEC | dsPIC/PIC24
;-------------------------------------------------------------------------------------------------------------
|
GETCC: MOV #VAL1,R2 ;POINT AT RETURN AREA | GETCC: mov #VAL1,w2
CLR (R2) ;INITIALIZE TO ZERO | clr.b [w2]
MOV #'',R1 ;SET UP DELIMITER FOR MAPCH | mov.b #' ',w1
|
10$: CALL MAPCH ;GET CHARACTER FROM INPUT | 1: call MAPCH
BCS 30$ ;BR IF END OF CONSTANT | bra CS,3f
CMP R2,#VAL1+2 ;TEST IF TOO MANY CHARACTERS | cp.b w2,#VAL1+2
BHIS 20$ ;BR IF YES | bra GT,2f
MOVB R0,(R2) ;OTHERWISE SAVE THE CHARACTER | mov.b w0,[w2]
20$: INC R2 ;IN ANY CASE, ADVANCE THE POINTER | 2: inc w2,w2
BR 10$ ;AND CONTINUE | bra 1b
|
30$: CMP R2,#VAL1+2 ;WERE THERE TOO MANY CHARACTERS? | 3: cp.b w2,#VAL1+2
BLOS 40$ ;BR IF NOT | bra LT,4f
MOV #ERR04,R0 ;IF TOO MANY CHARACTERS | mov #ERR04,w0
CALL ERROR1 ;COMPLAIN ;01 | call ERROR1
|
40$: RETURN ; | 4: return
|
;+
; ** GETNAM - READ AN IDENTIFIER INTO NB
;
; THIS ROUTINE READS THE FIRST 8. CHARACTERS INTO NB. IF THE
; IDENTIFIER IS TOO LONG THE EXTRA CHARACTERS ARE DISCARDED.
;
; CHARACTERS ARE CLASSIFIED BY LOOKING IN THE JUMP TABLE
; FOR ADDRESSES ADV85 (NUMERICS) AND ADV155 (ALPHABETICS).
; THIS IS FAIRLY DIRTY, BUT WILL PROBABLY REMAIN.
;
; USES:
; R0, R1, R2
;-
|
;-------------------------------------------------------------------------------------------------------------
; DEC | dsPIC/PIC24
;-------------------------------------------------------------------------------------------------------------
GETNAM: MOV #NB,R1 ;POINT AT THE NAME BUFFER | GETNAM: mov #NB,w1
|
10$: MOV R0,R2 ;CLASSIFY THE CHARACTER | 1: mov w0,w2
ASL R2 | sl w2,w2
MOV ADVTAB(R2),R2 | mov.b [w2+ADVTAB],w2
CMP R2,#ADV85 ;NUMERIC (0 TO 9) | cp.b w2,#ADV85
BEQ 20$ ;YES | bra Z,2f
CMP R2,#ADV155 ;ALPHABETIC (A TO Z, a TO z, _, $) | cp.b w2,#ADV155
BNE 40$ ;NO, END OF IDENTIFIER | bra NZ,4f
CMP R0,#'$ ;HACK, $ -> TILDE ;02+ | cp.b w0,#'$'
BNE 20$ ;NO HACK TODAY | bra NZ,2f
MOV #176,R0 ;YES, FIX IT UP ;02- | mov #'~',w0
|
20$: CMP R1,#NB+8. ;IF THE CHARACTER FITS | 2: cp w1,#NB+8
BHIS 30$ | bra GT,3f
MOVB R0,(R1)+ ;SAVE IT IN THE BUFFER | mov.b w0,[w1+]
|
30$: CALL GETC ;GRAB THE NEXT CHARACTER, AND | 3: call GETC
BCC 10$ ;CONTINUE | bra NC,1b
BR 50$ ;END OF FILE DELIMITED IDENTIFIER | bra 5f
|
40$: CALL UNGETC ;PUT LAST (BAD) CHARACTER BACK | 4: call UNGETC
50$: CLRB (R1) ;TERMINATE THE STRING ;07 | 5: clr.b [w1]
RETURN | return
|