But first
Question 0: Read about how RISC machines can forward data from one instruction to another rather than waiting for it to pass through the registers. There are some questions in that document that you should think about a little, and ask about if you need advice, but you don't have to do them now. I just want to be sure that you've learned a little about forwarding while you have a chance, and before you have to answer questions about it in a future tutorial.
Now, back to machine code...
If you really were going to program in machine code, you could perhaps sit in front of the machine (really, the machine, not a monitor connected to the machine) and manipulate some switches on the front to set a binary word, and then press a button to deposit that word in the machine's memory at an address that you specify in the same way.
Unfortunately, ISEM simulates the SPARC instruction set architecture, but it doesn't simulate the process of being able to edit the machine's memory directly. It does allow you to edit the contents of registers directly (display the registers, and then click on a register whose value you want to edit and look at the edit data entry box at the bottom of the window). So, we could load a small program that as we step through would store the contents of register 10 in successive addresses, so long as register 11 stays zero. Once register 11 changes from zero the program would jump to the first stored value and then it would execute those numbers that you have manually put in register 10 which have then been stored in the computer's memory.
.text start: nop ! An ordinary instruction to get isem started .word 0x03000010 ! machine code for a sethi instruction .word 0x82106000 ! machine code for an or instruction .word 0xc4004000 ! machine code for a load .word 0xca006004 ! machine code for another load etc .word 0x91d02000 ! machine code for trap 0(The machine code used in the example is part of text1.s)
Enter the following words as just described, and check that the machine code you've entered works as it should.
0xb2100000 0xb2060019 0xb0a62001 0x12bffffe 0x01000000 0x91d02000What does it do? (It might look familiar!)
argument:.
Hand assemble your program into machine code (hexadecimal).
Now enter your program as above (as hex numbers, not as assembly
code!) and explore
its execution. Continue to step through your program. Does it
work? If it does, then you can call yourself a machine code programmer!
.text set loop, %r3 ld [%r3],r10 add %r0, %r0, %r5 add %r0, %r0, %r2 loop: add %r2, 0, %r2 add %r5, 1, %r5 add %r10, %r5, %r10 st %r10, [%r3] cmp %r5, %r24 ble loop nop ta 0
Comp226 August 2013