写道
#include <stdio.h>
#include <stdlib.h>
#define N 10
void Arraysum(int len, int *A, int *B, int *C)
{
// int k = len;
// do
// {
// k--;
// C[k] = A[k] + B[k];
// } while (k > 0);
__asm__(//".text"
//".globl main"
"main:"
"##########################################################"
"# Note: pseudo-instruction la becomes lui followed by ori"
"la $t0, length # t0 = address of word before array[0], length"
"lw $t2, 0($t0) # t2 = length"
"sll $t2, $t2, 2 # multiply length by 4 to make t2 = length in bytes"
"add $t1, $t2, $t0 # t1 is initial value for k, address of A[k-1], since base is at t0 + 4"
"j test # jump to test at end of loop"
"loop: lw $t3, 0($t1) # t2 = A[k]"
"add $t4, $t1, $t2 # t4 = address of B[k]"
"lw $t5, 0($t4) # t5 = B[k]"
"add $t5, $t5, $t3 # t5 = A[k] + B[k]"
"add $t4, $t4, $t2 # t4 = address of C[k]"
"sw $t5, 0($t4) # C[k] = A[k] + B[k]"
"addi $t1, $t1, -4 # k--"
"test:"
"bne $t1, $t0, loop # loop test"
"################################################################"
"li $v0, 17 # set codes for end syscall"
"li $a0, 0");
// "syscall # end program");
}
main()
{
int Array1[N];
int Array2[N];
int output[N];
// Init input data
for (int i = 0; i < N; i++) {
Array1[i] = rand()%10;
Array2[i] = rand()%10;
}
Arraysum(N, Array1, Array2, output);
printf("Array1: \n");
for (int i = 0; i < N; i++) {
printf("%d ", Array1[i]);
printf(" ");
}
printf("\nArray2: \n");
for (int i = 0; i < N; i++) {
printf("%d ", Array2[i]);
printf(" ");
}
printf("\nOutput: \n");
for (int i = 0; i < N; i++) {
printf("%d ", output[i]);
printf(" ");
}
}
#include <stdlib.h>
#define N 10
void Arraysum(int len, int *A, int *B, int *C)
{
// int k = len;
// do
// {
// k--;
// C[k] = A[k] + B[k];
// } while (k > 0);
__asm__(//".text"
//".globl main"
"main:"
"##########################################################"
"# Note: pseudo-instruction la becomes lui followed by ori"
"la $t0, length # t0 = address of word before array[0], length"
"lw $t2, 0($t0) # t2 = length"
"sll $t2, $t2, 2 # multiply length by 4 to make t2 = length in bytes"
"add $t1, $t2, $t0 # t1 is initial value for k, address of A[k-1], since base is at t0 + 4"
"j test # jump to test at end of loop"
"loop: lw $t3, 0($t1) # t2 = A[k]"
"add $t4, $t1, $t2 # t4 = address of B[k]"
"lw $t5, 0($t4) # t5 = B[k]"
"add $t5, $t5, $t3 # t5 = A[k] + B[k]"
"add $t4, $t4, $t2 # t4 = address of C[k]"
"sw $t5, 0($t4) # C[k] = A[k] + B[k]"
"addi $t1, $t1, -4 # k--"
"test:"
"bne $t1, $t0, loop # loop test"
"################################################################"
"li $v0, 17 # set codes for end syscall"
"li $a0, 0");
// "syscall # end program");
}
main()
{
int Array1[N];
int Array2[N];
int output[N];
// Init input data
for (int i = 0; i < N; i++) {
Array1[i] = rand()%10;
Array2[i] = rand()%10;
}
Arraysum(N, Array1, Array2, output);
printf("Array1: \n");
for (int i = 0; i < N; i++) {
printf("%d ", Array1[i]);
printf(" ");
}
printf("\nArray2: \n");
for (int i = 0; i < N; i++) {
printf("%d ", Array2[i]);
printf(" ");
}
printf("\nOutput: \n");
for (int i = 0; i < N; i++) {
printf("%d ", output[i]);
printf(" ");
}
}
相关推荐
AT&T汇编和Intel的区别Brennan's Guide to Inline Assembly
The article describes differences in inline assembly of gcc and VC++
This is meant to be an introduction to inline assembly under DJGPP.
inline assembly code
GCC 内嵌汇编的语法 详细解析,解压之后是一个HTML文件
This HOWTO explains the use and usage of the inline assembly feature provided by GCC. There are only two prerequisites for reading this article, and that’s obviously a basic knowledge of x86 assembly...
包括两个文件,一个GCC Inline Assembly HOWTO,一个IBM的文档Inline assembly for x86 in Linux Putting the pieces together
Chapter 13, “Using Inline Assembly,” shows how to incorporate assembly language routines directly in your C or C++ language programs. Inline assembly language is often used for “hard-coding” quick...
翻译原文为GCC-Inline-Assembly-HOWTO,介绍gcc内联汇编的使用方法。
Creating inline assembly macro functions 386 Summary 387 Chapter 14: Calling Assembly Libraries 389 Creating Assembly Functions 389 Compiling the C and Assembly Programs 391 Compiling assembly source ...
how to write assemble code for gcc. Gcc inline assemble code explaination.
Linux内核设计与实现-第三版 Table of Contents 1 Introduction to the Linux ...Inline Assembly 19 Branch Annotation 19 No Memory Protection 20 No (Easy) Use of Floating Point 20 Small, Fixed-Size Stack 20
Inline assembly in C code
Simply add a new block to the file real/assembly.h which implements the required inline assembly functions for your processor. Something like <br>... #elif defined NEW_PROCESSOR <br>/* ...
A fast RLE encoding and decoding implementation. It uses inline assembly functions.
Inline assembly for x86 in Linux,Putting the pieces together
a tutorial on how to implement and optimize mutexes with gcc inline assembly
Inline Assembly Section F.1. HP-UX C Compilers Section F.2. GCC Compiler for Linux Section F.3. Intel Compilers for Linux References Bibliography Answers and Hints for Selected ...
GCC内联汇编(INLINE ASSEMBLY) 什么是内联汇编(Inline assembly)? 1、这是GCC对C语言的扩张,是在C代码里面去写汇编代码 2、可以直接在C的语句中插入汇编指令 有何用处? 1、C语言不足以完成所有...