嵌入式系统:汇编

本文介绍了一个使用汇编语言的小作业,通过if-else语句找出一组数中的最大值和最小值,并将两者相乘。该作业演示了如何在汇编语言中进行数值比较和操作,为理解低级语言的控制流程提供了实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一个小作业。
找出最大值和最小值,然后相乘。

我使用if-else语句实现。

			Min	EQU	50H 
			Max EQU 51H
			ORG 0H
			
START:		
			MOV 40H, #24 ; 16 numbers from address 40H
			MOV 41H, #2
			MOV 42H, #63
			MOV 43H, #11
			MOV 44H, #28
			MOV 45H, #8
			MOV 46H, #9
			MOV 47H, #14
			MOV 48H, #16
			MOV 49H, #35
			MOV 4AH, #54
			MOV 4BH, #13
			MOV 4CH, #6
			MOV 4DH, #17
			MOV 4EH, #32
			MOV 4FH, #25
			MOV R0, #41H ; the pointer to travel in the array
			MOV Max, 40H ; begin from the first number 
			MOV Min, 40H 
			MOV R2, #15 ; the number to control loop, 15 times
			
			
LP1:		
			MOV A, @R0
			CJNE A, Max, NEXT1 ; compare A with Max			

NEXT1:		
			JC	NEXT2 ; if A < Max, then go to NEXT2
			MOV Max, A ; if A >= Max, then MAX = A
			INC R0 ; Move to the last number by one step
			SJMP LP2 ; end one loop
				
NEXT2:		
			CJNE A, Min, NEXT3 ; compare A with Min

NEXT3:		
			JNC LP2 ; if A >= Min, then back to the loop
			MOV Min, A ; if A < Min, them Min = A
			INC R0
			SJMP LP2 

LP2:		
			DJNZ R2, LP1 ; control loop times, 15 times totally

MULTI:		
			MOV A, Min
			MOV B, Max
			MUL AB
			MOV 52H, A
			MOV 53H, B

END ; Min is 2, Max is 63, Min*Max is 126, after run this project, register A is 0x7e = 126, because it save 
	; Low 8 bits, and register B is 0x00, beacause it save High 8 bits. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值