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

📄 计算器.s

📁 八位整数的+-*/
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module _计算器.c
	.area text(rom, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.area vector(rom, abs)
	.org 4
	jmp _int0
	.area text(rom, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
_code::
	.blkb 2
	.area idata
	.word 63
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.blkb 2
	.area idata
	.word 6
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.blkb 2
	.area idata
	.word 91
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.blkb 2
	.area idata
	.word 79
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.blkb 2
	.area idata
	.word 102
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.blkb 2
	.area idata
	.word 109
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.blkb 2
	.area idata
	.word 125
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.blkb 2
	.area idata
	.word 7
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.blkb 2
	.area idata
	.word 127
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.blkb 2
	.area idata
	.word 111
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.dbsym e code _code A[20:10]i
_i::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.dbsym e i _i c
	.area text(rom, con, rel)
	.dbfile E:\avr工程\计算器\计算器\程序\计算器.c
	.dbfunc e int0 _int0 fV
;              t -> R20
	.even
_int0::
	st -y,R0
	st -y,R1
	st -y,R2
	st -y,R3
	st -y,R4
	st -y,R5
	st -y,R6
	st -y,R7
	st -y,R8
	st -y,R9
	st -y,R16
	st -y,R17
	st -y,R18
	st -y,R19
	st -y,R20
	st -y,R22
	st -y,R23
	st -y,R24
	st -y,R25
	st -y,R26
	st -y,R27
	st -y,R30
	st -y,R31
	in R0,0x3f
	st -y,R0
	xcall push_xgsetF000
	.dbline -1
	.dbline 13
; #include<iom16v.h>
; #include<macros.h>
; #include<math.h>
; #define uint unsigned int 
; #define uchar unsigned char
; #pragma interrupt_handler int0:2
; 
; uint code[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
; uchar i=0;
; uchar sign;
; 
; void int0()
; {		uchar t=255;
	.dbline 13
	ldi R20,255
	.dbline 14
;  	 GICR&=~BIT(6);             //先关闭中断,因为用的是键盘反转扫描法,故扫描过程中会出现
	in R24,0x3b
	andi R24,191
	out 0x3b,R24
	.dbline 16
; 	 	                        //电平交替变化,为防止再次触发中断先关闭中断
;  	 if(keyscan()!=255)         //检测按键是否有效
	xcall _keyscan
	cpi R16,255
	ldi R30,0
	cpc R17,R30
	breq L5
X0:
	.dbline 17
; 	 i=keyscan();
	xcall _keyscan
	sts _i,R16
L4:
	.dbline 18
; 	 while(t--);                //按键扫描会导致电平不稳定,延时一小段时间等待波形稳定
L5:
	.dbline 18
	mov R22,R20
	clr R23
	subi R20,1
	tst R22
	brne L4
X1:
L7:
	.dbline 19
; 	 while((PIND|=BIT(2))==0);  //检测按键是否抬起
L8:
	.dbline 19
	in R20,0x10
	ori R20,4
	out 0x10,R20
	tst R20
	breq L7
X2:
	.dbline 21
; 	 
; 	 GICR|=BIT(6);
	in R24,0x3b
	ori R24,64
	out 0x3b,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	xcall pop_xgsetF000
	ld R0,y+
	out 0x3f,R0
	ld R31,y+
	ld R30,y+
	ld R27,y+
	ld R26,y+
	ld R25,y+
	ld R24,y+
	ld R23,y+
	ld R22,y+
	ld R20,y+
	ld R19,y+
	ld R18,y+
	ld R17,y+
	ld R16,y+
	ld R9,y+
	ld R8,y+
	ld R7,y+
	ld R6,y+
	ld R5,y+
	ld R4,y+
	ld R3,y+
	ld R2,y+
	ld R1,y+
	ld R0,y+
	reti
	.dbsym r t 20 c
	.dbend
	.dbfunc e delay _delay fV
;              i -> R20,R21
;              j -> R22,R23
;              t -> R16,R17
	.even
_delay::
	xcall push_xgsetF000
	.dbline -1
	.dbline 27
; 	
; }
; 
; 
; void delay(uint t)
; {
	.dbline 29
;  	 uint i,j;
;  	 for(i=0;i<t;i++)
	clr R20
	clr R21
	xjmp L14
L11:
	.dbline 30
; 	 	for(j=0;j<1141;j++);
	clr R22
	clr R23
	xjmp L18
L15:
	.dbline 30
L16:
	.dbline 30
	subi R22,255  ; offset = 1
	sbci R23,255
L18:
	.dbline 30
	cpi R22,117
	ldi R30,4
	cpc R23,R30
	brlo L15
X3:
L12:
	.dbline 29
	subi R20,255  ; offset = 1
	sbci R21,255
L14:
	.dbline 29
	cp R20,R16
	cpc R21,R17
	brlo L11
X4:
	.dbline -2
L10:
	.dbline 0 ; func end
	xjmp pop_xgsetF000
	.dbsym r i 20 i
	.dbsym r j 22 i
	.dbsym r t 16 i
	.dbend
	.dbfunc e InitC_0 _InitC_0 fV
	.even
_InitC_0::
	.dbline -1
	.dbline 35
; }
; 
; 
; void InitC_0()        //配置c口高四位为输出,低四位为带上拉电阻的输入
; { 	 DDRC=0xf0; 
	.dbline 35
	ldi R24,240
	out 0x14,R24
	.dbline 36
; 	 PORTC=0x0f;   
	ldi R24,15
	out 0x15,R24
	.dbline -2
L19:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e InitC_1 _InitC_1 fV
	.even
_InitC_1::
	.dbline -1
	.dbline 39
; }
; void InitC_1()        //配置c口低四位为输出,高四位为带上拉电阻的输入
; {
	.dbline 40
;  	 DDRC=0x0f;
	ldi R24,15
	out 0x14,R24
	.dbline 41
; 	 PORTC=0xf0;  
	ldi R24,240
	out 0x15,R24
	.dbline -2
L20:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e show _show fV
;              j -> R10
;              i -> R12
	.even
_show::
	st -y,R10
	st -y,R12
	mov R10,R18
	mov R12,R16
	.dbline -1
	.dbline 47
; }   
; 
; 
; 
; void show(uchar i,uchar j)           //在数码管的第i位,显示数字j
; {
	.dbline 48
;  	 PORTA=0x00;	 	
	clr R2
	out 0x1b,R2
	.dbline 49
; 	 PORTA|=BIT(i);
	ldi R16,1
	mov R17,R12
	xcall lsl8
	in R2,0x1b
	or R2,R16
	out 0x1b,R2
	.dbline 50
; 	 PORTB=0x02;
	ldi R24,2
	out 0x18,R24
	.dbline 51
; 	 PORTB=0x00;
	clr R2
	out 0x18,R2
	.dbline 52
; 	 PORTA=0x00;
	out 0x1b,R2
	.dbline 53
; 	 PORTA=~code[j];
	ldi R24,<_code
	ldi R25,>_code
	mov R30,R10
	clr R31
	lsl R30
	rol R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	com R2
	com R3
	out 0x1b,R2
	.dbline 54
; 	 PORTB=0X01;
	ldi R24,1
	out 0x18,R24
	.dbline 55
; 	 PORTB=0X00;
	clr R2
	out 0x18,R2
	.dbline -2
L21:
	.dbline 0 ; func end
	ld R12,y+
	ld R10,y+
	ret
	.dbsym r j 10 c
	.dbsym r i 12 c
	.dbend
	.dbfunc e display_1 _display_1 fV
;              j -> y+0
;              x -> R10
;              t -> R12
;            wei -> R10
;              i -> y+14
	.even
_display_1::
	xcall push_arg4
	xcall push_xgsetF0FC
	sbiw R28,4
	.dbline -1
	.dbline 60
; 	// delay(1);
; }
;  	 	         
; void display_1(long i)         //检测一整数的位数并显示
; {  	 
	.dbline 61
; 	 if(i==0)show(0,0);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R2,y+14
	ldd R3,y+15
	ldd R4,y+16
	ldd R5,y+17
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L23
X5:
	.dbline 61
	clr R18
	clr R16
	xcall _show
	xjmp L24
L23:
	.dbline 63
; 	 else
; 	 {
	.dbline 64
; 	 	uchar t=9;
	ldi R24,9
	mov R12,R24
	.dbline 65
;      	uchar wei,x=0;
	clr R10
	.dbline 66
; 	 	long j=10000000;
	ldi R20,128
	ldi R21,150
	ldi R22,152
	ldi R23,0
	std y+0,R20
	std y+1,R21
	std y+2,R22
	std y+3,R23
	xjmp L26
L25:
	.dbline 68
;  	 	while(x==0)             //检测i的位数
; 	 	{ 	x=(i>=j);
	.dbline 68
	ldd R2,y+0
	ldd R3,y+1
	ldd R4,y+2
	ldd R5,y+3
	ldd R6,y+14
	ldd R7,y+15
	ldd R8,y+16
	ldd R9,y+17
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlt L28
X6:
	ldi R24,1
	ldi R25,0
	movw R14,R24
	xjmp L29
L28:
	clr R14
	clr R15
L29:
	mov R10,R14
	.dbline 69
; 	 		j/=10;
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R16,y+0
	ldd R17,y+1
	ldd R18,y+2
	ldd R19,y+3
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall div32s
	std y+0,R16
	std y+1,R17
	std y+2,R18
	std y+3,R19
	.dbline 70
; 			t--;
	dec R12
	.dbline 71
; 	 	}
L26:
	.dbline 67
	tst R10
	breq L25
X7:
	.dbline 73
; 	 
; 	 	for(wei=0;wei<t;wei++)  //从低位到高位依次显示
	clr R10
	xjmp L33
L30:
	.dbline 74
; 	 	{  show(wei,i%10);
	.dbline 74
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R16,y+14
	ldd R17,y+15
	ldd R18,y+16
	ldd R19,y+17
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall mod32s
	mov R18,R16
	mov R16,R10
	xcall _show
	.dbline 75
; 	       i/=10;
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R16,y+14
	ldd R17,y+15
	ldd R18,y+16
	ldd R19,y+17
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall div32s
	std y+14,R16
	std y+15,R17
	std y+16,R18
	std y+17,R19
	.dbline 76
; 	 	}
L31:
	.dbline 73
	inc R10
L33:
	.dbline 73
	cp R10,R12
	brlo L30
X8:
	.dbline 77
; 	}
L24:
	.dbline -2
L22:
	.dbline 0 ; func end
	adiw R28,4
	xcall pop_xgsetF0FC
	adiw R28,4
	ret
	.dbsym l j 0 L
	.dbsym r x 10 c
	.dbsym r t 12 c
	.dbsym r wei 10 c
	.dbsym l i 14 L
	.dbend
	.dbfunc e display _display fV
;              t -> R12
;              j -> y+8
;              x -> R10
;            wei -> R10
;              n -> y+4
;              i -> y+0
;              a -> y+22
	.even
_display::
	xcall push_arg4
	xcall push_xgsetF0FC
	sbiw R28,12
	.dbline -1
	.dbline 82
; }
; 	  	 	
; 	
; void display(float a)
; { 	  
	.dbline 84
; 	 float n;
; 	 long i=(long)a;	
	ldd R16,y+22
	ldd R17,y+23
	ldd R18,y+24
	ldd R19,y+25
	xcall fpint
	std y+0,R16
	std y+1,R17
	std y+2,R18
	std y+3,R19
	.dbline 85
; 	 n=a-i;
	ldd R2,y+22
	ldd R3,y+23
	ldd R4,y+24
	ldd R5,y+25
	ldd R16,y+0
	ldd R17,y+1
	ldd R18,y+2
	ldd R19,y+3
	xcall long2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R2
	movw R18,R4
	xcall fpsub2
	std y+4,R16
	std y+5,R17
	std y+6,R18
	std y+7,R19
	.dbline 86
; 	 if(n==0)display_1(i);
	ldd R2,y+4
	ldd R3,y+5
	ldd R4,y+6
	ldd R5,y+7
	ldi R16,<L37
	ldi R17,>L37
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R2
	movw R18,R4
	xcall fpcmp2
	brne L35
X9:
	.dbline 86
	ldd R16,y+0
	ldd R17,y+1
	ldd R18,y+2
	ldd R19,y+3
	xcall _display_1
	xjmp L36
L35:
	.dbline 87
; 	 else{
	.dbline 88
; 	 	  uchar t=9;
	ldi R24,9
	mov R12,R24
	.dbline 89
;      	  uchar wei,x=0;
	clr R10
	.dbline 90
; 	 	   long j=10000000;
	ldi R20,128
	ldi R21,150
	ldi R22,152
	ldi R23,0
	std y+8,R20
	std y+9,R21
	std y+10,R22
	std y+11,R23
	xjmp L39
L38:
	.dbline 93
; 	 
; 	 	   while(x==0)             //检测i的位数
; 	 	   { 	x=(i>=j);
	.dbline 93
	ldd R2,y+8
	ldd R3,y+9
	ldd R4,y+10
	ldd R5,y+11
	ldd R6,y+0
	ldd R7,y+1
	ldd R8,y+2
	ldd R9,y+3
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlt L41
X10:
	ldi R24,1
	ldi R25,0
	movw R14,R24
	xjmp L42
L41:
	clr R14
	clr R15
L42:
	mov R10,R14
	.dbline 94
; 	 			j/=10;
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R16,y+8
	ldd R17,y+9
	ldd R18,y+10
	ldd R19,y+11
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall div32s
	std y+8,R16
	std y+9,R17
	std y+10,R18
	std y+11,R19
	.dbline 95
; 				t--;
	dec R12
	.dbline 96
; 	 		}
L39:
	.dbline 92
	tst R10
	breq L38
X11:
	.dbline 98
; 					
; 			show(8-t,10);	
	ldi R18,10
	ldi R16,8
	sub R16,R12
	xcall _show
	.dbline 99
; 			for(wei=8-t;wei<8;wei++)  //先确定最低位在数码管的位置,然后从低位到高位依次显示
	ldi R24,8
	mov R10,R24
	sub R10,R12
	xjmp L46
L43:
	.dbline 100
; 	 		{  show(wei,i%10);        //整数部分
	.dbline 100
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R16,y+0
	ldd R17,y+1
	ldd R18,y+2
	ldd R19,y+3
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall mod32s
	mov R18,R16
	mov R16,R10
	xcall _show
	.dbline 101
; 	       	   i/=10;
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	ldd R16,y+0
	ldd R17,y+1
	ldd R18,y+2
	ldd R19,y+3
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall div32s
	std y+0,R16
	std y+1,R17
	std y+2,R18
	std y+3,R19
	.dbline 102
; 	 		}
L44:

⌨️ 快捷键说明

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