Assembly 如何在汇编程序(SPARC)中找到整数数组的最小值和最大值?
我必须编写一个汇编程序来查找int数组的最小值(作为指针从C输入程序) 有人能告诉我怎么做吗?或者至少如何在汇编程序中存储/访问数组 通常,变量由连续的缓冲区访问,例如:Assembly 如何在汇编程序(SPARC)中找到整数数组的最小值和最大值?,assembly,int,min,sparc,Assembly,Int,Min,Sparc,我必须编写一个汇编程序来查找int数组的最小值(作为指针从C输入程序) 有人能告诉我怎么做吗?或者至少如何在汇编程序中存储/访问数组 通常,变量由连续的缓冲区访问,例如: subcc %i0, 2, %l0 但是我不知道如何使用数组。请记住,在C表达式中,arr[I]实际上相当于*(arr+I) 要访问数组中的值,您需要计算它的地址-它是arr+i*sizeof(int)。然后,您可以使用ld,st指令进行读写。我已经设法做到了以下几点: .global findminmax ! .
subcc %i0, 2, %l0
但是我不知道如何使用数组。请记住,在C表达式中,
arr[I]
实际上相当于*(arr+I)
要访问数组中的值,您需要计算它的地址-它是
arr+i*sizeof(int)
。然后,您可以使用ld
,st
指令进行读写。我已经设法做到了以下几点:
.global findminmax !
.proc 4 !
!
findminmax: !
save %sp, -96, %sp !
ld [%i0], %l0 !
mov %l0, %l2 !
mov %l0, %l3 !
!
loop: !
subcc %i1, 1, %l0 !
bneg end !
nop !
!
ld [%i0], %l1 !
!
subcc %l2, %l1, %l0 !
bneg newmax !
nop !
!
subcc %l1, %l3, %l0 !
bneg newmin !
nop !
!
back: !
add %i0, 4, %i0 !
sub %i1, 1, %i1 !
ba loop !
nop !
end: !
st %l2, [%i2] !
st %l3, [%i3] !
ret !
restore !
!
newmax: !
mov %l1, %l2 !
ba back !
nop !
newmin: !
mov %l1, %l3 !
ba back !
nop !