单片机编程,采用汇编语言的循环结构,找出从内部40H到49H单元中存放的最小的数,并把它放在内部RAM的50H单

2024-12-28 14:13:26
推荐回答(5个)
回答1:

ORG 0000H
MAIN:
MOV 50H, #0 ;先用0充当最小值.
MOV R0, #40H ;起始地址.
LOOP: MOV A, @R0 ;取出一个数.
CLR C
SUBB A, 50H ;减去最小值.
JNC NEXT ;无借位(即够减)转移.
MOV 50H, @R0 ;否则就用这个数当最小值.
NEXT: INC R0 ;转向下一个地址.
CJNE R0, #4AH, LOOP;不到最后就转到前面去循环比较.

SJMP $ ;暂停.

END ;完.

回答2:

ORG 00H
START:
MOV SP,#5FH
CLR RS0
CLR RS1
CLR A
MOV B,#00H
MOV R0,#40H
MOV A,@R0
LOOP:
INC R0
MOV 03H,@R0
MOV B,03H
PUSH ACC
PUSH B
DIV AB
JZ NEXT
POP ACC
POP B
AJMP END_LOOP
NEXT:
POP B
POP ACC
END_LOOP:
CJNE R0,#49H,LOOP
MOV 50H,A
SJMP $
END

回答3:

ORG 0000H
MOV R0,#41H
MOV R7,#10
MOV 50H,40H
LOOP: MOV A,@R0
CJNE A,50H,$+3
JNC LOOP1
XCH A,50H
LOOP1: INC R0
DJNZ R7,LOOP
SJMP $
END

回答4:

START_ADDR EQU 40H
END_ADDR EQU 49H
DEST EQU 50H

ORG 0000H
MAIN:
MOV RO, #START
LOOP:
MOV A, R0,
MOV R1, A
INC R1
MOV A, @R0
CLR C
SUBB A, @R1
JC NEXT
NEXT:
SJMP OVERFLY
MOV A, @R0
MOV @R1, A
OVERFLY:
INC R0
CJNE R0, #END_ADDR - START_ADDR + 1, LOOP
MOV A, @END_ADDR
MOV @DEST, A

Note:The subroutine above just suit unsigned 8-bits comparasion.

回答5:

请参考