0

I am very new to coding. I am trying to understand how to write an instruction set, that is very simple. the requirement are these basics: read, write, add, subtract,enable loop/conditional operation. I was trying to find example codes, online but without any success. Does the programming language has to be machine code or can it be c?

Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61
Alexandra
  • 1
  • 1

1 Answers1

2

An ISA is a programming language. The programs are machine code.

An ISA is a set of rules for what exactly happens to the architectural state of the machine when running each possible instruction. e.g. binary 0101 xxyy might be a 2-operand add x,y instruction, where xx is a 2-bit destination register number, and yy is the source register number. The ISA would include rules for how flags are set, if you have a flag / condition-code register.

You don't write an ISA in another programming language.

You can design CPU hardware that implements the ISA (e.g. in verilog or VHDL I think). You can even simulate that design running a program written in machine code for your new ISA.

You can also write an interpreting emulator for that ISA, for example in C, which models the architectural state of the machine in C variables and an array for memory. The program would read machine code and decode instructions. Normally you'd design the ISA first, and then implement an emulator for it.


Another useful tool is an assembler, which translates text into machine code for your ISA. Text mnemonics for instructions and text register names only exist in the asm source.

Typically an ISA will standardize this, too, so it's possible to talk about machine code, but having an assembly language at all is not strictly necessary as part of an ISA. You can leave it up to users of the ISA to make up register names and mnemonics, and asm source syntax, for your ISA.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Thank you for this useful comment! You have already helped me a lot. My assignment says to write the cpu in c language and I assumed that I would have to write the ISA in C as well, because i do not know how to implement MIPS ( how to run it and dont know how to connect it to cpu that is coded in c). I was told to do emulation, but i don`t understand what it means exactly. So does this mean, that because I have to design the cpu in c, i can have a very simple instruction set, without using binary implementation? – Alexandra Mar 19 '19 at 18:27
  • @Alexandra: Ok, so as well as creating the ISA, you need to create a C emulator/interpreter for it. You could write an emulator for your ISA that reads a program in text assembly language, instead of binary machine code, if your assignment allows that simplification. But then you need to be able to jump to source lines for jump/branch instructions, and they're usually not fixed-width. – Peter Cordes Mar 19 '19 at 18:58