SlideShare a Scribd company logo
I am try to create a program that takes a user typed MIPS instruction (ex: add $6 $8 $10) then
turns that into its binary value.
but for some reason it will not work correctly. Also the code is not fully done but it shouldn't
effect anything
#include
#include
#include
int main () {
char str[50];
char op[3], rs[10], rt[10], rd[10], dtm[50];//, shamt[10], funt[10], immediat[20];
printf("Enter MIPS: ");
//Asks for the MIPS statement even with spaces
fgets(str, 50, stdin);
sscanf( str, "%s %s %s %s", op, rs, rt, rd );
//For R type of instructions
if(op == "add" || op == "addu" || op == "slt" || op == "sll" || op == "srl" || op == "sub"){
op == '000000';
// turn rs into binary
if(rs == '$0'){
rs == '00000';
}
elseif(rs == '$1'){
rs == '00001';
}
elseif(rs == '$2'){
rs == '00010';
}
elseif(rs == '$3'){
rs == '00011';
}
elseif(rs == '$4'){
rs == '00100';
}
elseif(rs == '$5'){
rs == '00101';
}
elseif(rs == '$6'){
rs == '00110';
}
elseif(rs == '$7'){
rs == '00111';
}
elseif(rs == '$8'){
rs == '01000';
}
elseif(rs == '$9'){
rs == '01001';
}
elseif(rs == '$10'){
rs == '01010';
}
elseif(rs == '$11'){
rs == '01011';
}
elseif(rs == '$12'){
rs == '01100';
}
elseif(rs == '$13'){
rs == '01101';
}
elseif(rs == '$14'){
rs == '01110';
}
elseif(rs == '$15'){
rs == '01111';
}
elseif(rs == '$16'){
rs == '10000';
}
//turn rt into binary
if(rt == '$0'){
rt == '00000';
}
elseif(rt == '$1'){
rt == '00001';
}
elseif(rt == '$2'){
rt == '00010';
}
elseif(rt == '$3'){
rt == '00011';
}
elseif(rt == '$4'){
rt == '00100';
}
elseif(rt == '$5'){
rt == '00101';
}
elseif(rt == '$6'){
rt == '00110';
}
elseif(rt == '$7'){
rt == '00111';
}
elseif(rt == '$8'){
rt == '01000';
}
elseif(rt == '$9'){
rt == '01001';
}
elseif(rt == '$10'){
rt == '01010';
}
elseif(rt == '$11'){
rt == '01011';
}
elseif(rt == '$12'){
rt == '01100';
}
elseif(rt == '$13'){
rt == '01101';
}
elseif(rt == '$14'){
rt == '01110';
}
elseif(rt == '$15'){
rt == '01111';
}
elseif(rt == '$16'){
rt == '10000';
}
//turn all rd into binary
if(rd == '$0'){
rd == '00000';
}
elseif(rd == '$1'){
rd == '00001';
}
elseif(rd == '$2'){
rd == '00010';
}
elseif(rd == '$3'){
rd == '00011';
}
elseif(rd == '$4'){
rd == '00100';
}
elseif(rd == '$5'){
rd == '00101';
}
elseif(rd == '$6'){
rd == '00110';
}
elseif(rd == '$7'){
rd == '00111';
}
elseif(rd == '$8'){
rd == '01000';
}
elseif(rd == '$9'){
rd == '01001';
}
elseif(rd == '$10'){
rd == '01010';
}
elseif(rd == '$11'){
rd == '01011';
}
elseif(rd == '$12'){
rd == '01100';
}
elseif(rd == '$13'){
rd == '01101';
}
elseif(rd == '$14'){
rd == '01110';
}
elseif(rd == '$15'){
rd == '01111';
}
elseif(rd == '$16'){
rd == '10000';
}
printf("%s %s, %s, %s ", op, rd, rs, rt );
}
//For I type of instructions
elseif(op == 'addi' || op == 'lui' || op == 'ori' || op == 'lw' || op == 'sw' ){
}
//printf("%s %s = %s + %sn", op, rd, rs, rt );
return(0);
}

More Related Content

PDF
Im having difficulty with the directives i figured out a duplicatio.pdf
PPT
14941634.ppt
PPTX
Binary and hex input/output (in 8086 assembuly langyage)
PDF
Lenguaje ensamblador EMU8086
PPT
EMBEDDED SYSTEMS 4&5
PDF
Taller practico emu8086_galarraga
PPTX
ECE-3567-Lecture-2-Spring-2025 for beginners
PDF
Taller Ensambladores
Im having difficulty with the directives i figured out a duplicatio.pdf
14941634.ppt
Binary and hex input/output (in 8086 assembuly langyage)
Lenguaje ensamblador EMU8086
EMBEDDED SYSTEMS 4&5
Taller practico emu8086_galarraga
ECE-3567-Lecture-2-Spring-2025 for beginners
Taller Ensambladores

Similar to I am try to create a program that takes a user typed MIPS instructio.pdf (20)

PDF
I need help getting my mips program completed this are the full inst.pdf
PPT
1344 Alp Of 8086
PPT
ARM Fundamentals
PDF
Emulador de ensamblador emu8086
DOCX
cs47_proj_sourceCS47_proj_alu_normal.asm.include .cs47_proj.docx
PDF
The ProblemUsing C programming language write a program that simul.pdf
PDF
Finish the program below that does several bit-wise manipulations of.pdf
PPT
Instructions_introductionM2.1.about.microcontrollerppt
PPT
Chapter 2 instructions language of the computer
PPTX
Uc 2(vii)
PPTX
Instruction Set Architecture: MIPS
PDF
8051 assembly programming
PPT
Microcontroller instruction set
PPT
Al2ed chapter13
PPTX
C Homework Help
PDF
ARM programming basics for data typeswith examples
PDF
Embedded systems ppt ii
PDF
8051 micro controllers Instruction set
DOC
Instruction set summary
I need help getting my mips program completed this are the full inst.pdf
1344 Alp Of 8086
ARM Fundamentals
Emulador de ensamblador emu8086
cs47_proj_sourceCS47_proj_alu_normal.asm.include .cs47_proj.docx
The ProblemUsing C programming language write a program that simul.pdf
Finish the program below that does several bit-wise manipulations of.pdf
Instructions_introductionM2.1.about.microcontrollerppt
Chapter 2 instructions language of the computer
Uc 2(vii)
Instruction Set Architecture: MIPS
8051 assembly programming
Microcontroller instruction set
Al2ed chapter13
C Homework Help
ARM programming basics for data typeswith examples
Embedded systems ppt ii
8051 micro controllers Instruction set
Instruction set summary

More from allystraders (20)

PDF
Supplemental knowledge conversion processes have been added to the E.pdf
PDF
Supongamos que Musashi, un economista de un programa de radio AM, y .pdf
PDF
Suponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdf
PDF
Suponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdf
PDF
Suppose researchers are about to draw a sample of 1450 observations .pdf
PDF
Suponga que el Congreso est� considerando un proyecto de ley que imp.pdf
PDF
Suppose that there are two groups of people in the economy. In group.pdf
PDF
Suppose that the Fed will increase the money supply. Which of the fo.pdf
PDF
Suppose that the body weights of Roborovski dwarf hamsters are norma.pdf
PDF
Suppose that in a particular country, the TFR fell to zero and remai.pdf
PDF
Suppose that disposable income, consumption, and saving in some coun.pdf
PDF
Suppose that 60 of students at Kansas State University have listene.pdf
PDF
Suppose Maria and Jamal both face the following individual loss dist.pdf
PDF
Suppose a random variable X has the following probability distributi.pdf
PDF
Suppose a country had a smaller increase in debt in 2011 than it had.pdf
PDF
how would implement empowerment techniques within a service Choose .pdf
PDF
How were the management controls at Siemens prior to the Bribery sca.pdf
PDF
How would I create this diagramRentTool Viewpoints � Technology .pdf
PDF
How well did Thaldorf interact with each member of the DMUOn what.pdf
PDF
How do increasing atmospheric CO2 emissions threaten sea creatures, .pdf
Supplemental knowledge conversion processes have been added to the E.pdf
Supongamos que Musashi, un economista de un programa de radio AM, y .pdf
Suponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdf
Suponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdf
Suppose researchers are about to draw a sample of 1450 observations .pdf
Suponga que el Congreso est� considerando un proyecto de ley que imp.pdf
Suppose that there are two groups of people in the economy. In group.pdf
Suppose that the Fed will increase the money supply. Which of the fo.pdf
Suppose that the body weights of Roborovski dwarf hamsters are norma.pdf
Suppose that in a particular country, the TFR fell to zero and remai.pdf
Suppose that disposable income, consumption, and saving in some coun.pdf
Suppose that 60 of students at Kansas State University have listene.pdf
Suppose Maria and Jamal both face the following individual loss dist.pdf
Suppose a random variable X has the following probability distributi.pdf
Suppose a country had a smaller increase in debt in 2011 than it had.pdf
how would implement empowerment techniques within a service Choose .pdf
How were the management controls at Siemens prior to the Bribery sca.pdf
How would I create this diagramRentTool Viewpoints � Technology .pdf
How well did Thaldorf interact with each member of the DMUOn what.pdf
How do increasing atmospheric CO2 emissions threaten sea creatures, .pdf

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
RMMM.pdf make it easy to upload and study
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Institutional Correction lecture only . . .
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Presentation on HIE in infants and its manifestations
102 student loan defaulters named and shamed – Is someone you know on the list?
Chinmaya Tiranga quiz Grand Finale.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
human mycosis Human fungal infections are called human mycosis..pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
RMMM.pdf make it easy to upload and study
STATICS OF THE RIGID BODIES Hibbelers.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
GDM (1) (1).pptx small presentation for students
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Institutional Correction lecture only . . .
Microbial diseases, their pathogenesis and prophylaxis
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
Presentation on HIE in infants and its manifestations

I am try to create a program that takes a user typed MIPS instructio.pdf

  • 1. I am try to create a program that takes a user typed MIPS instruction (ex: add $6 $8 $10) then turns that into its binary value. but for some reason it will not work correctly. Also the code is not fully done but it shouldn't effect anything #include #include #include int main () { char str[50]; char op[3], rs[10], rt[10], rd[10], dtm[50];//, shamt[10], funt[10], immediat[20]; printf("Enter MIPS: "); //Asks for the MIPS statement even with spaces fgets(str, 50, stdin); sscanf( str, "%s %s %s %s", op, rs, rt, rd ); //For R type of instructions if(op == "add" || op == "addu" || op == "slt" || op == "sll" || op == "srl" || op == "sub"){ op == '000000'; // turn rs into binary if(rs == '$0'){ rs == '00000'; } elseif(rs == '$1'){ rs == '00001'; } elseif(rs == '$2'){ rs == '00010'; } elseif(rs == '$3'){
  • 2. rs == '00011'; } elseif(rs == '$4'){ rs == '00100'; } elseif(rs == '$5'){ rs == '00101'; } elseif(rs == '$6'){ rs == '00110'; } elseif(rs == '$7'){ rs == '00111'; } elseif(rs == '$8'){ rs == '01000'; } elseif(rs == '$9'){ rs == '01001'; } elseif(rs == '$10'){ rs == '01010'; } elseif(rs == '$11'){ rs == '01011'; } elseif(rs == '$12'){ rs == '01100'; } elseif(rs == '$13'){ rs == '01101'; } elseif(rs == '$14'){ rs == '01110'; } elseif(rs == '$15'){
  • 3. rs == '01111'; } elseif(rs == '$16'){ rs == '10000'; } //turn rt into binary if(rt == '$0'){ rt == '00000'; } elseif(rt == '$1'){ rt == '00001'; } elseif(rt == '$2'){ rt == '00010'; } elseif(rt == '$3'){ rt == '00011'; } elseif(rt == '$4'){ rt == '00100'; } elseif(rt == '$5'){ rt == '00101'; } elseif(rt == '$6'){ rt == '00110'; } elseif(rt == '$7'){ rt == '00111'; } elseif(rt == '$8'){ rt == '01000'; } elseif(rt == '$9'){ rt == '01001';
  • 4. } elseif(rt == '$10'){ rt == '01010'; } elseif(rt == '$11'){ rt == '01011'; } elseif(rt == '$12'){ rt == '01100'; } elseif(rt == '$13'){ rt == '01101'; } elseif(rt == '$14'){ rt == '01110'; } elseif(rt == '$15'){ rt == '01111'; } elseif(rt == '$16'){ rt == '10000'; } //turn all rd into binary if(rd == '$0'){ rd == '00000'; } elseif(rd == '$1'){ rd == '00001'; } elseif(rd == '$2'){ rd == '00010'; } elseif(rd == '$3'){ rd == '00011'; }
  • 5. elseif(rd == '$4'){ rd == '00100'; } elseif(rd == '$5'){ rd == '00101'; } elseif(rd == '$6'){ rd == '00110'; } elseif(rd == '$7'){ rd == '00111'; } elseif(rd == '$8'){ rd == '01000'; } elseif(rd == '$9'){ rd == '01001'; } elseif(rd == '$10'){ rd == '01010'; } elseif(rd == '$11'){ rd == '01011'; } elseif(rd == '$12'){ rd == '01100'; } elseif(rd == '$13'){ rd == '01101'; } elseif(rd == '$14'){ rd == '01110'; } elseif(rd == '$15'){ rd == '01111'; }
  • 6. elseif(rd == '$16'){ rd == '10000'; } printf("%s %s, %s, %s ", op, rd, rs, rt ); } //For I type of instructions elseif(op == 'addi' || op == 'lui' || op == 'ori' || op == 'lw' || op == 'sw' ){ } //printf("%s %s = %s + %sn", op, rd, rs, rt ); return(0); }