MIPS寻址方式 编写MIPS汇编程序A[0]+A[1]+A[2]+A[3]=A[4] 怎么做啊?
- MIPS汇编程序
- 求一段完整的MIPS汇编代码?
- 求解计算机体系结构题。关于MIPS的。
- 用C语言设计这样一个程序: 设集合A={a[1],a[2],a[3]...a[m]}集合B={b[1],b[2],b[3]...b[n]}求A交B
MIPS汇编程序
现看的,可能不是太好,不过倒是能用-x-b
.data
str0: .asciiz "Primes in 1000:\n"
str1: .asciiz ",\n"
.text
.globl __start
__start:
la $a0, str0
li $v0, 4
syscall
li $t0, 2
j __test0
__l0:
li $t1, 1
li $t2, 2
j __test1
__l1:
div $t0, $t2
mfhi $t4
bne $t4, $0, __br1
move $t1, $0
__br1:
addi $t2, 1
__test1:
bne $t2, $t0, __l1
beq $t1, $0, __br0
move $a0, $t0
li $v0, 1
syscall
la $a0, str1
li $v0, 4
syscall
__br0:
addi $t0, 1
__test0:
li $t4, 100
bne $t0, $t4, __l0
li $v0, 10
syscall
----
有个事忘说了,这个真机上可能跑不了,那个模拟器模拟delay slot我没弄明白。
求一段完整的MIPS汇编代码?
代码如下:
(这个是百度得到的 )
~/ vi Hello.c
"Hello.c" [New file]
/* Example to illustrate mips register convention
* -Author: BNN
* 11/29/2001
*/
int addFunc(int,int);
int subFunc(int);
void main()
{
int x,y,z;
x= 1;
y=2;
z = addFunc(x,y);
}
int addFunc(int x,int y)
{
int value1 = 5;
int value2;
value2 = subFunc(value1);
return (x+y+value2);
}
int subFunc(int value)
{
return value--;
}
反汇编代码后的代码:
/* main Function */
0000000000000000 :
/*create a stack frame by moving the stack pointer 8
*bytes down and meantime update the sp value
*/
0: 27bdfff8 addiu $sp,$sp,-8
/* Save the return address to the current sp position.*/
4: afbf0000 sw $ra,0($sp)
8: 0c000000 jal 0
/* nop is for the delay slot */
c: 00000000 nop
/* Fill the argument a0 with the value 1 */
10: 24040001 li $a0,1
/* Jump the addFunc */
14: 0c00000a jal 28
/* NOTE HERE: Why we fill the second argument
*behind the addFunc function call?
* This is all about the "-O1" compilation optimizaiton.
* With mips architecture, the instruciton after jump
* will also be fetched into the pipline and get
* exectuted. Therefore, we can promise that the
* second argument will be filled with the value of
* integer 2.
*/
18: 24050002 li $a1,2
/*Load the return address from the stack pointer
* Note here that the result v0 contains the result of
* addFunc function call
*/
1c: 8fbf0000 lw $ra,0($sp)
/* Return */
20: 03e00008 jr $ra
/* Restore the stack frame */
24: 27bd0008 addiu $sp,$sp,8
/* addFunc Function */
0000000000000028 :
/* Create a stack frame by allocating 16 bytes or 4
* words size
*/
28: 27bdfff0 addiu $sp,$sp,-16
/* Save the return address into the stack with 8 bytes
* offset. Please note that compiler does not save the
* ra to 0($sp).
*Think of why, in contrast of the previous PowerPC
* EABI convention
*/
2c: afbf0008 sw $ra,8($sp)
/* We save the s1 reg. value into the stack
* because we will use s1 in this function
* Note that the 4,5,6,7($sp) positions will then
* be occupied by this 32 bits size register
*/
30: afb10004 sw $s1,4($sp)
/* Withe same reason, save s0 reg. */
34: afb00000 sw $s0,0($sp)
/* Retrieve the argument 0 into s0 reg. */
38: 0080802d move $s0,$a0
/* Retrieve the argument 1 into s1 reg. */
3c: 00a0882d move $s1,$a1
/* Call the subFunc with a0 with 5 */
40: 0c000019 jal 64
/* In the delay slot, we load the 5 into argument a0 reg
*for subFunc call.
*/
44: 24040005 li $a0,5
/* s0 = s0+s1; note that s0 and s1 holds the values of
* x,y, respectively
*/
48: 02118021 addu $s0,$s0,$s1
/* v0 = s0+v0; v0 holds the return results of subFunc
*call; And we let v0 hold the final results
*/
4c: 02021021 addu $v0,$s0,$v0
/*Retrieve the ra value from stack */
50: 8fbf0008 lw $ra,8($sp)
/*!!!!restore the s1 reg. value */
54: 8fb10004 lw $s1,4($sp)
/*!!!! restore the s0 reg. value */
58: 8fb00000 lw $s0,0($sp)
/* Return back to main func */
5c: 03e00008 jr $ra
/* Update/restore the stack pointer/frame */
60: 27bd0010 addiu $sp,$sp,16
/* subFunc Function */
0000000000000064 :
/* return back to addFunc function */
64: 03e00008 jr $ra
/* Taking advantage of the mips delay slot, filling the
* result reg v0 by simply assigning the v0 as the value
*of a0. This is a bug from my c source
* codes--"value--". I should write my codes
* like "--value", instead.
68: 0080102d move $v0,$a0
求解计算机体系结构题。关于MIPS的。
CAD
用C语言设计这样一个程序: 设集合A={a[1],a[2],a[3]...a[m]}集合B={b[1],b[2],b[3]...b[n]}求A交B
#include<stdio.h>
int main()
{
int a[100]={06},b[100]={0},i,j,n,m;
scanf ("%d",&n); //集合a的个数;
for (i = 0 ; i < n ; i++)
scanf ("%d",&a[i]); //读入集合a的元数 ;
scanf ("%d",&m); //集合b的个数;
for (i = 0 ; i < m ; i++)
scanf ("%d",&b[i]); //读入集合b的元数 ;
for (i = 0 ; i < n ; i++)
for (j = 0 ; j < m ;j ++)
if (a[i] == b[j]) //用枚举的思想找到a交b ,及他们相同的元素
printf("%5d",a[i]);
printf ("\n");
return 0;
}
//亲,希望可以帮助到你,如有疑问的话,请追问,嘻嘻