Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String MIPS。计算字符串中每个ascii符号的数量。_String_Assembly_Ascii_Mips - Fatal编程技术网

String MIPS。计算字符串中每个ascii符号的数量。

String MIPS。计算字符串中每个ascii符号的数量。,string,assembly,ascii,mips,String,Assembly,Ascii,Mips,我正在尝试用MIPS完成一项任务 需要用下一种方法比较两个字符串:计算两个字符串中从1到255的每个ascii符号的数量,并比较每个符号的值。 有一段时间,我用java编写了一段伪代码,只是为了可视化一个问题。我不明白的是,如何对字符串中的每个ascii字符进行“搜索” // array allAscii that suppose to contain all ascii symbols (i have made it containing all zeros bacause in thi

我正在尝试用MIPS完成一项任务

需要用下一种方法比较两个字符串:计算两个字符串中从1到255的每个ascii符号的数量,并比较每个符号的值。 有一段时间,我用java编写了一段伪代码,只是为了可视化一个问题。我不明白的是,如何对字符串中的每个ascii字符进行“搜索”

 // array allAscii that suppose to contain all ascii  symbols (i have made it
 containing all zeros bacause in this java code it is not that much important)
int[] allAscii = new int[255]               

String s1 = "ascii.";   // first string
String s2 = "asciiz,";   // second string    

int difference = 0;    

for(int i = 0; i< allAscii.length; i++){

    int count1 = 0;       //counter for the character of the string1
    int count2 = 0;       //counter for the character of the string1

    for(int k = 0; k<s1.length(); k++){
        if( s1.charAt(k) == allAscii[i]) count1++;              
    }           
    for(int l = 0; l<s2.length(); l++){
        if( s2.charAt(l) == allAscii[i]) count2++;
    }

    difference += Math.abs(count1- count2);         
}
//假设包含所有ascii符号的数组allAscii(我已经做了
包含所有零(因为在这段java代码中没有那么重要)
int[]allAscii=新int[255]
字符串s1=“ascii。”;//第一串
字符串s2=“asciiz,”;//二线
int差=0;
for(int i=0;ifor(int k=0;kExactly就像你在伪代码中做的那样。你能在MIPS中做循环和数组索引吗?这就是你所需要的一切。@Jester我怎么能指出我需要ascii符号数组的第一个元素?我能找出字符是否在“a”和“z”之间被压缩成这样:sge$t0,$a0,'sle$t1,$a0,'z',但我怎么能“迭代”呢在整个ascii数组上?不确定您的意思,如果您遵循java代码,用字符声明一个数组,然后将其起始地址加载到寄存器中,例如
la$a0,allAscii
,然后在循环中递增它,并以
($a0)
的形式访问项目。检查一些ascii表,普通ascii是7位值(0-127),通常存储为8位字节(0-255)(浪费1位)。您的Java示例尝试使用255个字符,这几乎是完整的字节范围(0-255是256个值,而不是255),这称为“扩展ASCII”,在每个平台上都有很大差异(128-255个字符的定义).无论如何,如果您想一想,就会发现Java代码是这样设计的,
i==allAscii[i]
,因此您可以完全删除该字符数组,只需循环0-255个字节值。就像字母
'A'
是字节值
65
。我的意思是
sge$t0,$a0,'A'
sge$t0,$a0,65
是同一条指令,
'A'
字母实际上是编译后的数字值,计算机本身是s不知道字母/字母或其他字符,它只看到设置/清除的位,按8位分组,可以解释为0到255之间的8位无符号值“字节”(Java有“有符号”字节,因此它将同一组8位解释为-128到+127之间的值),或者如果将其视为ASCII值,并在屏幕上显示值为
65
的字体字形,则通常普通字体将在该索引上包含大号字母A。