Arrays 如何将ASCII字符串按升序存储到数组中
我试图将逗号分隔的ASCII数字串转换为半字。然后将它们按升序排列在一个数组中。我知道如何得到半字,但问题是升序。按照我的方式,它读取一个字符,然后如果它不是null或逗号,它将把数字存储在一个变量中,然后一旦它到达一个逗号,它将两个ASCII数字组合成一个半字(除非只有一个数字)。我猜我会在那之后将其存储在数组中,但我不确定如何知道将其放在哪里。这是组装中的 编辑: 这是我所有的转换代码。最后,如果没有找到重复项,它将转到循环_end1,然后将其添加到数组中(这是我需要添加升序内容的地方)。如果找到了重复项,它将转到循环_end2,因此不会将其放入数组中。一旦达到null,即字符串结束,就可以完成。在“完成所有”中,它从字符串中的元素数减去数组中的元素数,以找到已消除的元素数。谢谢你的帮助Arrays 如何将ASCII字符串按升序存储到数组中,arrays,assembly,ascii,Arrays,Assembly,Ascii,我试图将逗号分隔的ASCII数字串转换为半字。然后将它们按升序排列在一个数组中。我知道如何得到半字,但问题是升序。按照我的方式,它读取一个字符,然后如果它不是null或逗号,它将把数字存储在一个变量中,然后一旦它到达一个逗号,它将两个ASCII数字组合成一个半字(除非只有一个数字)。我猜我会在那之后将其存储在数组中,但我不确定如何知道将其放在哪里。这是组装中的 编辑: 这是我所有的转换代码。最后,如果没有找到重复项,它将转到循环_end1,然后将其添加到数组中(这是我需要添加升序内容的地方)。如
L1:
mov a1, addrs #move the first char of string into 'a1'
sb fc, a1 #store the char in fc
cmp fc,0 #is the char null?
je done #if the char is null, youre done
jne L2 #if the char is not null goto L2
L2:
cmp fc,2C #is the char a comma?
jne L3
inc addrs
sub dige,dige,dige #make dige 0, the complicated way
jal L5 #comma has been found put the previous numbers in array
L3:
sub fc, fc,48 #turn to decimal from ASCII
cmp dige,1 #is this the second or first
jne L4
lb sd #holds second digit
sb sd,fc
add dige,dige,1
jal L1
L4:
lb fd #holds first digit
sb fd,fc
inc addrs
add dige,dige,1
L5:
cmp dige,2
jne L6
mov $t0,fd
sll fd,3 #this multipies the first digit by 2^3 (8). now add 2 more
add fd,fd,$t0
add fd,fd,$t0 #in total multiplies by 10 because fd*8+fd+fd=fd*10
add $t1,fd,sd
lh hw #holds halfword of number
sb hw,$t1
mov ecx,0
jal loop_start
L6:
lh hw
sb hw,fd
mov ecx,0 #inc counter to compare to array length
loop_start:
cmp ecx, ARRAY_LENGTH #does ecx equal the number of elem?
jge loop_end1
cmp hw,Array1[ecx*8]
add ecx,1
je loop_end2
jal loop_start
loop_end1:
mov [addra1],hw
add count,1
inc addra1
jal L1
loop_end2:
add count,1
jal L1
done:
sub count,count,ARRAY_LENGTH #subtracts array length from count to find number of elements eliminated
你能展示一些你尝试过的代码吗?这是哪个CPU的?该代码看起来像x86和MIPS汇编的hodge podge。。x86是什么代码?例如:
cmpecx,ARRAY\u LENGTH