All Projects → zakarialaoui10 → HIGH-TO-LOW

zakarialaoui10 / HIGH-TO-LOW

Licence: MIT license
in this repository you will find codes in C and their equivalence in MIPS Assembly

Programming Languages

assembly
5116 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to HIGH-TO-LOW

8086-cheatsheet
8086 Microprocessor Cheat sheet with Programs
Stars: ✭ 81 (+305%)
Mutual labels:  asm, microprocessor, low-level
LudOS
A toy monolithic kernel written in C++
Stars: ✭ 38 (+90%)
Mutual labels:  asm, low-level
System Bus Radio
Transmits AM radio on computers without radio transmitting hardware.
Stars: ✭ 5,831 (+29055%)
Mutual labels:  microprocessor, low-level
ersatz80
Z80+ARM=BUGS
Stars: ✭ 13 (-35%)
Mutual labels:  microcontroller, microprocessor
yams
YAMS: Awesome MIPS Server
Stars: ✭ 17 (-15%)
Mutual labels:  mips, mars
asmdot
[Unstable] Fast, zero-copy and lightweight (Arm | Mips | x86) assembler in (C | C++ | C# | Go | Haskell | Javascript | Nim | OCaml | Python | Rust).
Stars: ✭ 23 (+15%)
Mutual labels:  mips, asm
awesome-n64-development
A curated list of Nintendo 64 development resources including toolchains, documentation, emulators, example code, and more
Stars: ✭ 210 (+950%)
Mutual labels:  mips, asm
pumbaa
Python on Simba.
Stars: ✭ 61 (+205%)
Mutual labels:  microcontroller
FASM
Unofficial git history of flat assembler
Stars: ✭ 32 (+60%)
Mutual labels:  asm
RuntimeTransformer
Library for easily modifying loaded classes at runtime
Stars: ✭ 34 (+70%)
Mutual labels:  asm
Etripator
A PC-Engine disassembler
Stars: ✭ 16 (-20%)
Mutual labels:  asm
lwjson
Lightweight JSON parser for embedded systems
Stars: ✭ 66 (+230%)
Mutual labels:  microcontroller
RingBuffer
Classic ringbuffer with optional Stream interface
Stars: ✭ 53 (+165%)
Mutual labels:  low-level
uvmm
Virtual machine monitor for L4Re
Stars: ✭ 22 (+10%)
Mutual labels:  mips
uDevkit-SDK
Embedded systems SDK for Uniswarm boards and others (dsPIC33, dsPIC30, PIC24 and PIC32 compatible)
Stars: ✭ 14 (-30%)
Mutual labels:  microcontroller
open-electronics
📚 💻 Great Resources for Electronics Enthusiasts
Stars: ✭ 347 (+1635%)
Mutual labels:  microcontroller
xForth
Experimental Forth cross compiler for tiny devices
Stars: ✭ 53 (+165%)
Mutual labels:  microcontroller
f5-rest-client
F5 BIG-IP SDK for the Go programming language.
Stars: ✭ 49 (+145%)
Mutual labels:  asm
DigiOS
Mini OS emulator for Digispark (an Attiny85 based microcontroller).
Stars: ✭ 46 (+130%)
Mutual labels:  microcontroller
rebuild
Zero-dependency, reproducible build environments
Stars: ✭ 48 (+140%)
Mutual labels:  mips

In this repository you will find codes in C and their equivalence in MIPS Assembly

hello_world

C
#include<stdio.h>   
int main(){  
  printf("hello world"); 
  return 0;
}   
MIPS Assembly
.data
 msg: .asciiz "hello world"
.text
 li $v0,4
 la $a0,msg
 syscall

print_an_integer

C
#include<stdio.h>
int main(){
int number=2;
  printf("%d",number);
  return 0;
}
MIPS Assembly
.data
 number: .word 2
.text 
 li $v0,1 
 lw $a0,number
 syscall 

print_a_float

C
#include<stdio.h>
int main(){
float number=2.5;
  printf("%f",number);
  return 0;
}
MIPS Assembly
.data
 number: .float 2.5
.text
 li $v0,2
 lwc1 $f12,number
 syscall 

read_and_print_an_integer

C
#include<stdio.h>
int main(){
int a;
printf("enter an integer : ");
scanf("%d",&a);
printf("your integer is : ");
printf("%d",a);
return 0;
}
MIPS Assembly
.data
 msg1: .asciiz "enter an integer : "
 msg2: .asciiz "your integer is  : "
.text
 print_msg1:li $v0,4
           la $a0,msg1
           syscall 
 read_integer:li $v0,5
              syscall 
 la $s0,($v0) #save_integer_in_s0:
 print_msg2:li $v0,4
            la $a0,msg2
            syscall              
 print_integer:li $v0,1
               la $a0,($s0)
               syscall 

addition_of_2_integers

C
#include<stdio.h>
int main()
{
  int a,b,c;
  scanf("%d%d",&a,&b);
  c=a+b;
  printf("%d",c);
  return 0;
}
MIPS Assembly
li $v0,5
syscall
move $s0,$v0
li $v0,5
syscall
move $s1,$v0
add $s2,$s1,$s0
li $v0,1
move $a0,$s2
syscall

substraction_of_2_integers

C
#include<stdio.h>
int main()
{
  int a,b,c;
  scanf("%d%d",&a,&b);
  c=a-b;
  printf("%d",c);
  return 0;
}
MIPS Assembly
li $v0,5
syscall
move $s0,$v0
li $v0,5
syscall
move $s1,$v0
sub $s2,$s0,$s1
li $v0,1
move $a0,$s2
syscall 

if_else_statement

C
#include<stdio.h>
int main(){
int a=5,b=3,c=0;
if(a==b) c=a+b;
else c=a-b;
	printf("%d",c);
	return 0;
}
MIPS Assembly
li $t0,5       #a
li $t1,3       #b
li $t2,3       #c
beq $t0,$t1,if
j else
if:add $t2,$t0,$t1
else:sub $t2,$t0,$t1
print:
li $v0,1
move $a0,$t2
syscall 

nested_if

C
#include<stdio.h>
int main(){
int a=1;
int b=4;
int c;
if(a==1)
{
	c=a;
	if(b!=3){
		c+=b;
	}	
}
printf("%d",c);
}
MIPS Assembly
li $t0,1  #a
li $t1,4  #b
beq $t0,1,if
j print
if:
  la $t2,($t0)   #c
  beq $t1,3,print 
  add $t2,$t2,$t1
print:
li $v0,1
move $a0,$t2
syscall 

switch statement

C
#include<stdio.h>
int main(){
int a;
int b=0;
scanf("%d",&a);
switch(a){
	case 0:b=-1; break;
	case 1:b=0; break;
	default :b=1; break;
}
printf("%d",b);
}
MIPS Assembly
# a====>$s0
# b====>$s1
read_a:li $v0,5
       syscall 
       la $s0,($v0)
switch:
beq $s0,0,case0
beq $s0,1,case1
j default
case0:li $s1,-1
j print
case1:li $s1,0
j print
default:li $s1,1
print:
li $v0,1
move $a0,$s1
syscall 

Power

C
#include<stdio.h>
int main(){
	int x,n;
	scanf("%d%d",&x,&n);
	int i=0;
	int p=1;
	for(i=0;i<n;i++)
	p*=x;
	printf("%d",p);
}
MIPS Assembly
read_x:li $v0,5
       syscall 
       la $s0,($v0)
read_n:li $v0,5
       syscall 
       la $s1,($v0)
li $s2,1 #p
li $t0,0
loop:
beq $t0,3,print
mult $s2,$s0
mflo  $s2
addi $t0,$t0,1
j loop
print:
li $v0,1
move $a0,$s2
syscall 

Factoriel

C
#include<stdio.h>
int main(){
	int x;
	scanf("%d",&x);
	int i;
	int f=1;
	for(i=x;i>1;i--)
	f*=i;
	printf("%d",f);
}
MIPS Assembly
li $v0,5
syscall 
la $s0,($v0)
li $s2,1
la $t0,($s0)
loop:
beq $t0,1,print
mult $s2,$t0
mflo  $s2
subi $t0,$t0,1
j loop
print :
li $v0,1
la $a0,($s2)
syscall

the parity of a number using the rest of the division

C
#include<stdio.h>
int main(){
  int number;
  read:scanf("%d",&number);
  if(number%2==0){
    printf("even\n");
    goto read;
    }
  else printf("odd\n");
  goto read;
}
MIPS Assembly
.data 
 even : .asciiz "even\n"
 odd : .asciiz "odd\n"
 .text
read:li $v0,5
syscall
move $s0,$v0
li $t0,2
div $s0,$t0
mfhi $t1
beq $t1,0,iseven
li $v0,4
la $a0,odd
syscall 
j read
iseven: li $v0,4
      la $a0,even
      syscall
j read

the parity of a number using bitwise and operator

C
#include<stdio.h>
int main(){
  int number,c;
  read:scanf("%d",&number);
  if((number & 1)==0){
    printf("even\n");
    goto read;
    }
  else printf("odd\n");
  goto read;
}
MIPS Assembly
.data 
 even : .asciiz "even\n"
 odd : .asciiz "odd\n"
 .text
read:li $v0,5
syscall
move $s0,$v0
li $t0,2
andi $t0,$s0,1
beq $t0,0,iseven
li $v0,4
la $a0,odd
syscall 
j read
iseven: li $v0,4
      la $a0,even
      syscall
j read

swap 2 numbers using auxiliary variable

C
#include<stdio.h>
int main(){
  int a=3,b=7,c;
  c=a;
  a=b;
  b=c;
  print("%d\n%d",a,b);
  return 0;
}
MIPS Assembly
li $s0,3   #a
li $s1,7   #b
la $t0,($s0)
la $s0,($s1)
la $s1,($t0)
li $v0,1
la $a0,($s0)
syscall 
li $v0,1
la $a0,($s1)
syscall

swap 2 numbers using addition and subtraction

C
#include<stdio.h>
int main(){
  int a=3,b=7;
  a=a+b;
  b=a-b;
  a=a-b;
  print("%d\n%d",a,b);
  return 0;
}
MIPS Assembly
li $s0,3
li $s1,7
add $s0,$s0,$s1
sub $s1,$s0,$s1
sub $s0,$s0,$s1
li $v0,1
la $a0,($s0)
syscall 
li $v0,1
la $a0,($s1)
syscall 

swap 2 numbers using bitwise xor operator

C
#include<stdio.h>
int main(){
  int a=3,b=7;
  a=a^b;
  b=a^b;
  a=a^b;
  printf("%d\n%d",a,b);
  return 0;
}
MIPS Assembly
li $s0,3
li $s1,7
xor $s0,$s0,$s1
xor $s1,$s0,$s1
xor $s0,$s0,$s1
li $v0,1
la $a0,($s0)
syscall
li $v0,1
la $a0,($s1)
syscall   

Read and Print elements of an array

C
#include<stdio.h>
int main(){
	int arr[5];
	int i=0;
	//read
	for(i=0;i<5;i++){
	    scanf("%d",&arr[i]);
	}
	//print
	for(i=0;i<5;i++){
	    printf("%d",arr[i]);
	    printf(" ");
	}
}
MIPS Assembly
.data
 arr: .space 20    #(20=5*4(Size of word))
 space: .asciiz " "
.text 
 li $t0,0
 read:
 li $v0,5
 syscall 
 sw $v0,arr($t0)
 addi $t0,$t0,4
 blt $t0,20,read
 
 la $s0,arr
 li $t0,0
 print:
 li $v0,1
 lw $a0,($s0)
 syscall 
 addi $t0,$t0,4
 addi $s0,$s0,4
 li $v0,4
 la $a0,space
 syscall 
 blt $t0,20,print

Array's elements somme

C
#include<stdio.h>
int main(){
	int tab[10]={0,1,2,3,4,5,6,7,8,9};
	int s=0;
	int i=0;
	while(i<10){
		s+=*(tab+i); // s=s+tab[i]
		i++;
	}
	printf("%d",s);
	return 0;
}
MIPS Assembly
.data 
tab: .byte 0,1,2,3,4,5,6,7,8,9
.text 
main: 
la $t0, tab 
li $a0,0 #compteur
li $s0,0 #somme
loop:
lb $t1,($t0)
add $s0,$s0,$t1
addi $t0,$t0,1
addi $a0,$a0,1
bne $a0,10,loop

print a random integer belongs to the interval 0,10

C
#include<stdio.h>   
int main(){  
  
  return 0;
}   
MIPS Assembly

In order to get a random number we have to assign the register $a0 with the value 42. the value stored in $a1 represent the upper value of the generated random number

.text
#get random int belongs to the interval 0,10
li $v0,42
li $a1,10
syscall 
print:
 li $v0,1
 syscall 
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].