一.
汇编语言实现找到众数和最大值
直方图和众数有问题
.data
Scores: .byte 17,18,20,0,6,10,16,19,13,16,14,18,16,14
Last: .byte 16
histogram: .space 17
maximum: .space 2
mode: .space 2
.text
main:
clr.b R12 ;findnum
clr.b R13 ;start address
clr.b R14 ;end address
clr.b R15 ;maximum number
clr.b R10
clr.b R9
clr.b R8
clr.b R7
clr.b R6
call #len ;calculate length
clr.b R5 ;counter
mov.b R7,R5 ;R5=len
call #max
mov.b R15,maximum ;max number
;histogram:
clr.b R5 ;counter
clr.b R14
mov.b R7,R5 ;R5=len
mov.w R13,R11
mov.w #histogram,R10
loop1: ;each num appear times
mov.b @R11,R12
mov.w R10,R14
call #histo
mov.b R15,1(R14)
inc R10 ;next space
inc R11 ;next number
dec R5
jne loop1
;mode:
mov.w #histogram,R13
inc R13
mov.b R7,R5 ;R5=len
call #max
mov.b R15,mode
jmp $
max:
mov.w R13,R4
clr.w R15 ;max
mov.b @R4,R15 ;first number->a[i](max)
loop2:
inc R4 ;a[i+1]
mov.b @R4,R6
cmp.b R15,R6
jl notchange ;R6<R15
;ch ange
mov.b R6,R15 ;don't need @
notchange:
dec R5 ;len-1
;next loop
jne loop2
;find maximum number
ret
histo:
mov.w R13,R9
clr.w R15 ;count appear times
loop:
mov.b @R9,R8
cmp.b R8,R12
jne next ;R8!=R12
inc R15 ;counter+1
next:
inc R9
cmp.w R9,R14 ;is end?
jne loop
end:
ret
len:
mov.w #Scores,R13
mov.w #Last,R14
mov.w R14,R7
sub.w R13,R7
inc R7 ;length
ret