Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-02 - decus/20-0049/ibcd.mac
There are 2 other files named ibcd.mac in the archive. Click here to see a list.
	TITLE	IBCD	FUNCTION CONVERS ASCII TO BCD
	INTERNAL	IBCD
;
;PDP-10 ROUTINE TO PULL ASCII CODED CHARACTER FROM ALPHAMERIC
;STRING AND RETURN ITS BCD EQUIVALENT.
;
;THIS IS CALLED AS A FORTRAN FUNCTION WITH 2 ARGUMENTS, THE
;STRING ADDRESS AND THE SERIAL NUMBER OF THE CHARACTER DESIRED.
;THE BCD EQUIVALENT IS RETURNED IN ACCUMULATOR ZERO.
;LTTR=IBCD('THIS IS A STRING',9) IN A FORTRAN PROGRAM
;WOULD GIVE LTTR THE VALUE 17 (OCTAL 21), THE BCD CODE FOR A,
;THE 9TH CHARACTER IN THE STRING.
;
;DONALD BARTH, CHEMISTRY DEPT., HARVARD UNIVERSITY
;
	AC0=0			;AC TO RECEIVE BCD CODE
	AC1=1			;AC USED AS SCRATCH AREA
	AC2=16			;AC CONTAINING RETURN ADDRESS
IBCD:	0
;
;OBTAIN ASCII CHARACTER FROM STRING
;
	MOVE	AC0,	@1(AC2)	;MOVE SERIAL NUMBER TO AC0
	ADDI	AC0,	4	;ADD 4 AND DIVIDE BY 5 TO FIND
	IDIVI	AC0,	5	;OUT WHAT WORD IN STRING CONTAINS
	SOS		AC0	;THE DESIRED CHARACTER.
	ADD	AC0,	(AC2)	;ADD THIS TO STRING ADDRESS.
	IMULI	AC1,	7	;MULTIPLY REMAINDER (IN AC0+1)
	MOVN	AC1,	AC1	;BY 7 (ASCII CHARACTER IS 7 BITS)
	ADDI	AC1,	35	;AND SUBTRACT FROM 29 (OCTAL 35)
				;TO FIND NUMBER OF BITS TO RIGHT
				;OF THE CHARACTER.
	LSH	AC1,	36	;SHIFT NUMBER OF BITS RIGHT OF
				;BYTE INTO BITS 0-5 OF BYTE POINTER.
	IOR	AC1,	[000700000000]	;PUT BYTE SIZE (7) INTO
					;BITS 6-11 OF BYTE POINTER.
	HRR	AC1,	AC0	;PUT ADDRESS INTO BITS 18-35.
	LDB	AC0,	AC1	;OBTAIN CODE AND PLACE INTO AC0
;
;CONVERT CODE FROM 7 BIT ASCII TO 6 BIT BCD
;
	ADDI	AC0,	6	;ADD 6 TO AC0 TO INSURE THAT
				;DIVISION BY 6 WILL GIVE A
				;POSITIVE REMAINDER.
	IDIVI	AC0,	6	;DIVIDE BY 6, PLACING RESULT IN
				;AC0 AND REMAINDER IN AC0+1 (AC1)
	SOS		AC0	;SUBTRACT 1 FROM RESULT AND ADD
	ADDI	AC0,	TABLE	;TO ADDRESS OF FIRST TABLE ENTRY
				;TO OBTAIN ADDRESS OF TABLE
				;ENTRY CONTAINING THE CONVERSION
				;INFORMATION FOR PRESENT CHARACTER.
	IMULI	AC1,	6	;MULTIPLY BY 6 AND SUBTRACT FROM
	MOVN	AC1,	AC1	;30 (OCTAL 36) TO OBTAIN NUMBER
	ADDI	AC1,	36	;OF BITS TO RIGHT IN TABLE ENTRY.
	LSH	AC1,	36	;SHIFT NUMBER OF BITS TO RIGHT
				;OF BYTE INTO BITS 0 TO 5.
	IOR	AC1,	[000600000000]	;PUT BYTE SIZE (6) INTO
					;BITS 6 TO 11.
	HRR	AC1,	AC0	;PUT ADDRESS INTO BITS 18-35.
	LDB	AC0,	AC1	;CONVERT CODE AND PLACE INTO AC0.
	JRA	AC2,	2(AC2)	;RETURN
;
;FOLLOWING IS THE ASCII TO BCD CONVERSION TABLE.
;
TABLE:	BYTE(6)	60,60,60,60,60,60  ;CODES   0-  5
	BYTE(6)	60,60,60,60,60,60  ;CODES   6- 11
	BYTE(6)	60,60,60,60,60,60  ;CODES  12- 17
	BYTE(6) 60,60,60,60,60,60  ;CODES  18- 23
	BYTE(6) 60,60,60,60,60,60  ;CODES  24- 29
	BYTE(6)	60,60,60,60,60,60  ;CODES  30- 35  , , ,!,",#
	BYTE(6)	53,60,60,14,74,34  ;CODES  36- 41 $,%,&,',(,)
	BYTE(6)	54,20,73,40,33,61  ;CODES  42- 47 *,+,,,-,.,/
	BYTE(6)  0, 1, 2, 3, 4, 5  ;CODES  48- 53 0,1,2,3,4,5
	BYTE(6)  6, 7,10,11,60,60  ;CODES  54- 59 6,7,8,9,:,;
	BYTE(6)	60,13,60,60,60,21  ;CODES  60- 65 <,=,>,?,@,A
	BYTE(6)	22,23,24,25,26,27  ;CODES  66- 71 B,C,D,E,F,G
	BYTE(6)	30,31,41,42,43,44  ;CODES  72- 77 H,I,J,K,L,M
	BYTE(6)	45,46,47,50,51,62  ;CODES  78- 83 N,O,P,Q,R,S
	BYTE(6)	63,64,65,66,67,70  ;CODES  84- 89 T,U,V,W,X,Y
	BYTE(6)	71,60,60,60,60,60  ;CODES  90- 95 Z,[,\,],^,_
	BYTE(6)	60,21,22,23,24,25  ;CODES  96-101 @,a,b,c,d,e
	BYTE(6) 26,27,30,31,41,42  ;CODES 102-107 f,g,h,i,j,k
	BYTE(6)	43,44,45,46,47,50  ;CODES 108-113 l,m,n,o,p,q
	BYTE(6)	51,62,63,64,65,66  ;CODES 114-119 r,s,t,u,v,w
	BYTE(6)	67,70,71,60,60,60  ;CODES 120-125 x,y,z,{,|, 
	BYTE(6)	60,60, 0, 0, 0, 0  ;CODES 126-127
	END