⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opgave1.s

📁 坦尼保姆
💻 S
📖 第 1 页 / 共 2 页
字号:
	RET  topstck: PUSH stlg	! Print end of nstack message 	PUSH (_printf) 	SYS 	ADD  SP,4 	RET  sneg:	NOT  6(BX)	! negate value at top of nstack 	NOT  4(BX) 	NOT  2(BX) 	NOT  (BX) 	ADD  (BX),1 	ADC  2(BX),0 	ADC  4(BX),0 	ADC  6(BX),0 	RET  smin:   CALL sneg	! Subtraction is negation followed by addition 	CALL splus 	RET  splus:  MOV  SI,BX	! Add top two members on the nstack 	ADD  BX,8 	MOV  DI,BX 	CALL addsd 	RET  smul:	XOR  DX,DX	! Multiply top two members of the nstack 	MOV  SI,BX 	CMP  6(BX),0 	JGE  1f 	NOT  DX		! Multiplication is done on positive values, sign is 	CALL sneg	! saved and used later. So if negative negate. 1:	ADD  BX,8 	MOV  DI,BX 	CMP  6(BX),0 	JGE  1f 	NOT  DX		! Here we process the sign of the other operand 	CALL sneg 1:	CALL mulsd 	CMP  DX,0 	JE   1f 	CALL sneg 1:	RET  sdivi:	XOR  DX,DX	! Divide the second value of the nstack by the top 	MOV  SI,BX 	CMP  6(BX),0 	JGE  1f 	CALL sneg	! Again save the sign and process positive integers 	NOT  DX 1:	CALL dup 	ADD  BX,16 	MOV  DI,BX 	CMP  6(BX),0 	JGE  1f 	CALL sneg 	NOT  DX 1:	CALL divsd	! Call of the division operation. 	MOV  SI,oper1 	SUB  DI,8 	CALL cpsd 	MOV  SI,oper3 	MOV  DI,BX 	CALL cpsd 	CMP  DX,0 	JE   1f 	ADD  (DI),1 	ADC  2(DI),0 	ADC  4(DI),0 	ADC  6(DI),0 	CALL sneg 	SUB  BX,8 	CALL sneg 	SUB  BX,8 	CALL splus 	ADD  BX,8 1:	RET  srest:  CALL sdivi	! Determine the remainder by division. 	SUB  BX,8 	CALL sxchg 	ADD  BX,8 	RET  sprint: PUSH BX		! Prints all values on the nstack on a single line. 	MOVB (nlcr),' ' 1:	CMP  BX,stkend 	JGE  1f 	CALL snlcr 	ADD  BX,8 	JMP  1b 1:	MOVB (nlcr),'\n' 	PUSH stckm 	PUSH (_printf) 	SYS 	ADD  SP,4 	POP BX 	RET  separ:  snop: RET	! no op at white space  snlcr:	PUSH DX		! Print top of nstack 	MOV  DI,oper4 	MOV  SI,BX 	CALL cpsd 	MOV  SI,oper5 	CALL clrs 	MOV  (SI),TEN 	XOR  DX,DX 	CMP  6(BX),0 	JGE  1f 	NOT  DX 	XCHG BX,DI 	CALL sneg 	XCHG DI,BX 1:	PUSH BX 	MOV  BX,wrtln+510 	MOV  AX,(nlcr) 	MOV  (BX),AX 2:	CALL divsd		! Divide number by ten convert the remainder	 	MOV  SI,oper1 	DEC  BX 	MOVB AL,(SI) 	ADDB AL,'0'		! to an ascii symbol and put it in a buffer 	MOVB (BX),AL 	MOV  SI,oper3 	CALL cpsd 	MOV  SI,oper5 	CMP  6(DI),0 	JNE  2b 	CMP  4(DI),0 	JNE  2b 	CMP  2(DI),0 	JNE  2b 	CMP  (DI),0 	JNE  2b 	CMP  DX,0 	JE   1f 	DEC  BX 	MOVB (BX),'-' 1:	PUSH BX			! Print the buffer 	PUSH (_printf) 	SYS 	ADD  SP,4 	POP  BX 	POP  DX 	RET  dup:	MOV  SI,BX	! Duplicate top of nstack 	SUB  BX,8 	MOV  DI,BX 	CALL cpsd 	RET   cmpds:	! Compares 8-byte integers in (SI) and (DI). Result is 1 if (DI)>(SI); 	! 0 if (DI)=(SI); and  -1 if (SI)>(DI); return value is put in AX. 	PUSH CX 	MOV  AX,6(SI) 	MOV  CX,6(DI) 	CMP  CX,AX 	JL   6f         JG   7f 	MOV  AX,4(SI) 	CMP  4(DI),AX 	JB   6f         JA   7f 	MOV  AX,2(SI) 	CMP  2(DI),AX 	JB   6f         JA   7f 	MOV  AX,(SI) 	CMP  (DI),AX 	JB   6f         JA   7f 	MOV  AX,0 	POP CX 	RET 6:	MOV  AX,-1 	POP CX 	RET 7:	MOV  AX,1 	POP CX 	RET  snum:	MOV  SI,oper2		! Digit encountered in input. Assemble entire 	MOV  DI,oper1		! integer from the input buffer and push it 	CALL clrd		! onto the nstack 	AND  DX,15 	MOV  (DI),DX 1:	CMP  (nxtbuf),48 	JL   8f 	CMP  (nxtbuf),57 	JG   8f 	CALL cpds 	CALL dlshift 	CALL dlshift 	CALL addsd 	CALL dlshift 	CALL clrs 	CALL getcbuf 	AND  DX,15 	MOV  (SI),DX 	CALL addsd 	JMP  1b 8:	CALL pushd 	RET 	 inplmin: !+ of - tegengekomen als karretje 	mov bp, sp	mov ax, 2(bp)	CMP AX,'=' 	JE 1f 	CMP AX, '(' 	JE 1f 	CALL incutin 	RET 	 1:	PUSH AX 	CALL instack 	RET 		 inmldvrs:	!* of : tegengekomen als karretje 	mov bp, sp	mov ax, 2(bp)	CMP AX,'*' 	JE 1f 	CMP AX,':' 	JE 1f 	CMP AX,'~' 	JE 1f 	CALL instack 	RET 1:	CALL incutin 	RET 	  inneg:	!~ tegengekomen als karretje 	CMP  (nxtbuf),'~' 	JNE  1f		!bij wel equal: dubbele negatie, beide tekens overslaan. 	CALL getcbuf 	RET 1:	CMP  (nxtbuf),'=' 	JNE  2f		!bij wel equal: dubbele negatie, beide tekens overslaan. 	CALL inermes 	RET 2:	POP  AX 	CMPB AL,'~' 	JNE  3f 	CALL inermes 	RET 3:	PUSH AX 	CALL instack 	RET 	 inhs:	!) tegengekomen als karretje 	mov bp, sp	mov ax, 2(bp)	CMP AX,'=' 	JE 1f 	CMP AX,'(' 	JE 2f 	PUSH AX !herstel de stack 	CALL incutin 	pop ax	RET 1:	CALL inermes 	RET 2:	PUSH AX !herstel de stack 	CALL indestr 	RET 	 	 inpass: !blabla stuur het karretje meteen door 	MOVB (BX),DL !DX bevat de byte die ingelezen is door getcbyte 	inc bx 	RET  incutin: !stuur een karretje van Texas naar California 	mov bp, sp	mov dx, 2(bp)	MOVB (BX),DL 	INC BX 	MOV AX,(pinbuf) 	DEC AX 	MOV (pinbuf),AX 	!DEC pinbuf !zorg ervoor dat het karretje vooraan de lijn weer opnieuw gelezen wordt 	RET  indestr: !hijack karretjes 	!ADD SP,2 !verwijder het karretje van de stack 	!het andere karretje wordt automatisch genegeerd doordat getcbuf naar het volgende karakter gaat. 	RET 	 inerror: 	MOVB (inputb),'\0' 	MOV (pinbuf),inputb !zet pointer weer aan begin van inputb 	PUSH inermes	! Print error message 	PUSH (_printf) 	SYS 	ADD  SP,4 	RET  instack: !stuur het karretje naar Texas 	PUSH DX 	RET 	 inequ:	!= tegengekomen als karretje 	mov bp, sp	mov ax, 2(bp)	CMP AX,'=' 	JE 1f 	CMP AX,'(' 	JE 2f 	PUSH AX 	CALL incutin 	pop ax1:	RET !is dat een goeie STOP???? 2:	CALL inermes 	RET 	 .SECT .DATA .align 2null:		.WORD	0 _getchar:	.WORD	117 .ASCIZ "abcdefghijklmno"_printf:	.WORD	127 _putchar:	.WORD	122 one: _exit:	.WORD	1 _open:		.WORD	5 _read:		.WORD	3 _eof:		.WORD	0Xffff curbuf:	.WORD  0	! Current value of input buffer as word variable nxtbuf:	.WORD  0	! Next value of input buffer as word variable pinbuf:	.WORD  0	! Next position in input buffer to be put in nxtbuf  ! Next we get the 128 byte dispatch table which is used to jump to the ! indicated routines on a byte from the input buffer.  DTABLE:	.WORD	squit,	snop,	snop,	snop,	squit,	snop,	snop,	snop 	!	cntrl-0 cntrl-A cntrl-B cntrl-C cntrl-D cntrl-E cntrl-F bell 	.WORD	snop,	separ,	separ,	separ,	separ,	separ,	snop,	snop 	!	back	hortab	newline	vertab	newpag	carret	shout	shin 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop 	.WORD	separ,	snop,	snop,	snop,	snop,	srest,	snop,	snop 	!	space	!	"	#	$	%	&	' 	.WORD	snop,	snop,	smul,	splus,	snop,	smin,	snop,	snop 	!	(	)	*	+	,	-	.	/ 	.WORD	snum,	snum,	snum,	snum,	snum,	snum,	snum,	snum 	!	0	1	2	3	4	5	6	7 	.WORD	snum,	snum,	sdivi,	snop,	snop,	snop,	snop,	snop 	!	8	9	:	;	<	=	>	? 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop 	!	@	A	B	C	D	E	F	G 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop 	!	H	I	J	K	L	M	N	O 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop 	!	P	Q	R	S	T	U	V	W 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	sprint,	snop 	!	X	Y	Z	[	\	]	^	- 	.WORD	snop,	snop,	snop,	snop,	dup,	snop,	snop,	snop 	!	`	a	b	c	d	e	f	G 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop 	!	h	i	j	k	l	m	n	O 	.WORD	spop,	squit,	recall,	store,	snop,	snop,	snop,	snop 	!	p	q	r	s	t	u	v	W 	.WORD	sxchg,	snop,	snop,	snop,	snop,	snop,	sneg,	snop 	!	x	y	z	{	|	}	~	delete  ! <b>De conversie tabel voor infix to postfix</b> INTABLE: .WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop  	!	cntrl-0 cntrl-A cntrl-B cntrl-C cntrl-D cntrl-E cntrl-F bell 	.WORD	snop,	inpass,	inpass,	inpass,	inpass,	inpass,	snop,	snop 	!	back	hortab	newline	vertab	newpag	carret	shout	shin 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop 	.WORD	inpass,	snop,	snop,	snop,	snop,	inmldvrs,	snop,	snop 	!	space	!	"	#	$	%	&	' 	.WORD	instack,	inhs,	inmldvrs,	inplmin,	snop,	inplmin,	snop,	snop 	!	(	)	*	+	,	-	.	/ 	.WORD	inpass,	inpass,	inpass,	inpass,	inpass,	inpass,	inpass,	inpass 	!	0	1	2	3	4	5	6	7 	.WORD	inpass,	inpass,	inmldvrs,	snop,	snop,	inequ,	snop,	snop 	!	8	9	:	;	<	=	>	? 	.WORD	snop,	inpass,	inpass,	inpass,	inpass,	inpass,	inpass,	inpass 	!	@	A	B	C	D	E	F	G 	.WORD	inpass,	inpass,	inpass,	inpass,	inpass,	inpass,	inpass,	inpass 	!	H	I	J	K	L	M	N	O 	.WORD	inpass,	inpass,	inpass,	inpass,	inpass,	inpass,	inpass,	inpass 	!	P	Q	R	S	T	U	V	W 	.WORD	inpass,	inpass,	inpass,	snop,	snop,	snop,	inpass,	snop 	!	X	Y	Z	[	\	]	^	- 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop 	!	`	a	b	c	d	e	f	g 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	snop,	snop 	!	h	i	j	k	l	m	n	o 	.WORD	snop,	snop,	inpass,	snop,	snop,	snop,	snop,	snop 	!	p	q	r	s	t	u	v	w 	.WORD	snop,	snop,	snop,	snop,	snop,	snop,	inneg,	snop 	!	x	y	z	{	|	}	~	delete  nlcr:	 .ASCIZ "\n" shfterr: .ASCIZ "Overflow in shift. Number loaded is too large.\n" eofmes:	 .ASCIZ "Getchar reads end of file.\n" symerro: .ASCIZ "Error encountered in input line.\n" varmes:	 .ASCIZ "Variable not defined.\n" nulmes:	 .ASCIZ "Division by zero is refused.\n" stckm:	 .ASCIZ "Stack\n" stlg:	 .ASCIZ "Stack underflow encountered.\n" inermes: .ASCIZ "Error in infix notation encountered.\n"  .SECT .BSS nstack:	.SPACE 8192		! This is the main 8-byte integer stack stkend: wrtln: .SPACE 512	! End of nstack, and start of write buffer oper1:	.SPACE 8		! Five scratch variables for multiplication oper2:	.SPACE 16		! and division  oper3:	.SPACE 8 oper4:	.SPACE 8 oper5:	.SPACE 8 varbuf: .SPACE 216		! Space reserved for variables A-Z inputb: .SPACE 512		! The main input buffer 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -