1 / 19

Modifying the Standard Instruction Set

Modifying the Standard Instruction Set. Save everything:. Make sure that the directory that contains has, mas and sim belong to your path Make a tarball of all standard instruction set files, copy it to a working directory and expand the tarball:. [pletcha@archimedes asm]$ echo $PATH

melody
Download Presentation

Modifying the Standard Instruction Set

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Modifying the Standard Instruction Set

  2. Save everything: • Make sure that the directory that contains has, mas and sim belong to your path • Make a tarball of all standard instruction set files, copy it to a working directory and expand the tarball: [pletcha@archimedes asm]$ echo $PATH bin:/usr/sbin:.../home/pletcha/Courses/asm:/home/pletcha/bin $ cd <working directory> $ tar cf standard.tar s.* $ mkdir StandardModifications/Proj1 $ cp standard.tar StandardModifications/Proj1 $ cd StandardModifications/Proj1 $ tar xf standard.tar

  3. What things should look like: [pletcha@archimedes Proj1]$ ls s.cfg s.has s.hor s.hst standard.tar s.txt s.vas s.ver s.vst [pletcha@archimedes Proj1]$

  4. Files we need to change: • s.cfg: This file contains a list of all pertinent assembly language instructions and the CPU configuration – number of CPUs, • s.has: files containing the course code for all the assembly language instructions in the Standard Instruction Set.

  5. Example: • Prepare a special register for saving the stack pointer and two new instructions that save and recover the stack pointer: • sav: This saves the stack register to the new sv register. • rec: This puts the value of the stack pointer stored in sv back into the sp register.

  6. s.cfg 30 swap 0 ; mnemonic and number of operands for opcode F7 31 sav 0 ; mnemonic and number of operands for opcode F8 32 rec 0 ; mnemonic and number of operands for opcode F9 33 34 35 %% ; Part 2 (reg names in number order starting with reg 6) 36 37 pc ; register 6 38 sp ; register 7 39 ac ; register 8 40 ir ; register 9 41 dc ; register A 42 sv ; register B - used for saving the stack pointer (sav & rec instructions)

  7. s.has • First we notice that the decoding is already done for us for the new instructions we will write. 47 LF_1: dc = left(dc); if (s) goto LF_11; 48 LF_10: dc = left(dc); if (s) goto LF_101; 49 LF_100: dc = left(dc); if (s) goto LF_9; 50 goto LF_8;

  8. Now we code at labels LF_8 and LF_9: /***************************************************************/ / Available Opcodes / /***************************************************************/ LF_8: /------------------------ SAV ----------------------- sv = sp; goto fetch; LF_9: /------------------------ REC ----------------------- sp = sv; goto fetch; LF_A: /---------------------------------------------------- LF_B: /----------------------------------------------------

  9. Testing our new Instructions: • First we need to save the new instruction set in a tar ball and then copy the contents of the tarball to the working directory. [pletcha@archimedes Proj1]$ ls s.cfg s.has s.hor s.hst standard.tar s.txt s.vas s.ver s.vst [pletcha@archimedes Proj1]$ tar cf sav_rec.tar s.* [pletcha@archimedes Proj1]$ ls sav_rec.tar s.cfg s.has s.hor s.hst standard.tar s.txt s.vas s.ver s.vst [pletcha@archimedes Proj1]$ tar tf sav_rec.tar s.cfg s.has s.hor s.hst s.txt s.vas s.ver s.vst [pletcha@archimedes Proj1]$ grep sav s.cfg sav 0 ; mnemonic and number of operands for opcode F8 sv ; register B - used for saving the stack pointer ; (sav & rec instructions)

  10. What next: • Remember the program shown in Chapter 4 where we swapped out the stack pointer and made it point to an array of numbers. We then added up all the numbers. • We will execute the same program again but this time we will use sav and rec to save the stack pointer. • Let's call this version of the program sav_rec.mas

  11. !s ; needed to ensure we use s.hor and s.cfgsav ; save the stack pointer ldc table swap ld count ja test loop: ld sum addr 0 st sum dloc 1 ; sp now points to &table[i] ld count sub @1 st count test: jnz loop ldc msg sout ld sum dout ldc '\n' aoutrec ; recover the stack pointer halt msg: dw “sum = “ @1: dw 1 count: dw 10 sum: dw 0 table: dw 56 dw -8 dw 444 ...

  12. Assembling and Running the new Program: • Just as before we use mas to assemble and sim to run. • This time, run from inside sim and when all done print out the registers – r • You'll see the following:even though we know sp was swapped out and used to step through the list of numbers. 12: rec /F9 00/ sp=000A/0000 13: halt /FFFF / Machine inst count = 5D (hex) = 93 (dec) ---- [T7] r* pc = 0014 sp = 0000 ac = 000A

  13. Lab Exercise: • In all versions of the table sum exercise we use the ac register for three purposes – sum up the entries in the table, check jump condition and decrement the counter variable. • Let's start by changing how we test the jump condition. • We will introduce a new index register and have the jnz instruction jump on the new register – ct – being non-zero. • Create a new register called ct.

  14. Lab Exercise: 37 %% ; Part 2 (reg names in number order starting with reg 6) 38 39 pc ; register 6 40 sp ; register 7 41 ac ; register 8 42 ir ; register 9 43 dc ; register A 44 sv ; register B - used for saving the stack pointer (sav & rec instructions) 45 ct ; register C - used for counting in loops, etc

  15. Lab Exercise: • We need to look at the microcode of all the jump instructions except ja. They all involve passing the ac register through the ALU and then testing to see if the z-flag is set. • We can replace this by replacing the command 0 = ac; with 0 = ct; Now we don't care which registers were involved in theprevious operation that sent data through the ALU. LD: /------------------------- JNZ ---------------------- / 0 = ac; if (z) goto fetch; 0 = ct; if (z) goto fetch; pc = ir & xmask; goto fetch;

  16. Lab Exercise: • Finally, we need our special index register with its own decrement instruction. • Start by modifying the s.cfg file. • We'll need two new instructions • init: with 0 arguments, copies the contents of ac into ct • dec: with 0 arguments, decrements ct by 1 • Add both of these to s.cfg.

  17. Lab Exercise: 30 swap 0 ; mnemonic and number of operands for opcode F7 31 sav 0 ; mnemonic and number of operands for opcode F8 32 rec 0 ; mnemonic and number of operands for opcode F9 33 init 0 ; mnemonic and number of operands for opcode FA 34 dec 0 ; mnemonic and number of operands for opcode FB 35 36

  18. Lab Exercise: • Now we need to add the new instructions to s.has and rebuild s.hor. • Now it is time to produce a new copy of the original program that uses the new instructions – sav, rec, init and dec as well as the new version of jnz. • Once your new program is working properly and adds the numbers to 344, save everything. Proj 1$ tar cf sav_rec.tar s.* sav_rec.mas

  19. More Lab Exercises: • Stat a new project by creating a new project directory – StandardModifications/Proj2 • Copy standard.tar this directory and expand it • Complete Problem 6.19 • Start up a new project - Proj3 – and implement Problem 6.20 • In implementing 6.20 we need to remember that inside the execute part of the instruction (after fetch and decode) we need to fetch again twice; once to get the address and once to get the value stored at that address.

More Related