Practice Exericse 11 Answers

  1. Write a short C function that takes in a virtual address and translates it to a physical one, using global variables BA (base address) and FL (field length) as exemplified in Fig. 4. If there is an error, it prints out an error message and ends the program by doing exit(1); Otherwise, it returns the physical address.
               int dynaddrtran (int virtual_address)
               {
                    if (virtual_address > FL) {
                         printf ("Address too large.\n");
                         exit(1);
                    }
                    return BA + virtual_address;
               }

  1. Some systems may have a protection scheme whereby the ending address is stored in a register, sort of like the FL (field length) register discussed in the chapter. Discuss how this scheme is better, worse or just the same as storing the field length. Just to be clear on what we mean, the "Field Length" register in this new scheme would store 3600 instead of 1100, as shown in Fig. 4.
It is better in a way because you can "see" what the last legal address is. In the CDC system you would have to add FL to BA to get the last legal address.
But it is worse because the new physical address (virtual_address + BA) has to be computed before comparing it to the ending address, so this method takes more time. in the CDC method, the comparison with FL and addition to BA can happen in parallel, thereby saving time.

  1. You might think that your personal computer would never have need of multiprogramming or round-robin job scheduling since there is only one user using it at any given time. Think of why this chain of reasoning is wrong and why you should have multiprogramming.
It is unlikely that more than one human user would be using your PC at the same time but you might want to have your PC run more than one program simultaneously. For example, you might be editing a document at the same time as the network email program is sending or receiving mail or while some fancy graphics program is morphing an image. So there are often multiple "virtual users" today on a PC. And you might also connect more than 1 monitor and more than 1 keyboard to your machine even still.
  1. OS/3, a new super-duper operating system marketed by HAL Corp., is so amazing that it will even read the future and predict stock market fluctuations, making its users billionaires. It only runs on the Hinbell 80786 chip which runs at 50 MIPS (million instructions per second). OS/3 takes over control of the processor after user jobs run for one second. Then it does about 87,000,000 instructions before returning control to the user job. What is the overhead of OS/3?
50 MIPS --> 50,000,000 instructions per second, so 87,000,000 instructions would take 1.74 seconds (87 / 50).

The user takes 1 second and the OS takes up an additional 1.74 seconds, so one "turnaround" time would be 2.74 seconds. See picture below.

1.74 / 2.74 = .635 or about 64%


  1. The IBM 360 had many base registers, not just one, and they were actually just the general purpose registers R0 through R15 which ordinary user programs could inspect and alter.
a.) Why would the FL register approach outlined in Section 11.5 not work for this system?

 

because the user program might be broken into several separate chunks, and probably is if there can be separate base registers. The FL method only works when there is one big contiguous chunk of memory.

  b.) Why was it safe to put the base address or base addresses into registers which users could change? Wouldn't this give them access to every location in memory, thereby circumventing security?

 

No, because the IBM uses key-protection on its memory. A user job might be able to generate any address of real memory, but when it sends the address to the memory and the keys won't match, the memory will refuse to do the operation.

  c.) If the CDC's operating system needed to move a job around in memory while it was running (probably due to the need to compact memory), what would the OS have to do to get the addressing to still work out correctly?

 

It would merely have to put the new starting address in the base address register.

  d.) Why couldn't jobs be moved around in the IBM 360 once they started?

 

because we don't know which registers out of the 16 general purpose registers are being used for addressing and which are being used for data (ordinary calculations). So the OS doesn't know which regs it can and should change.

  1. The following CSC-1 program was compiled and linked as though it were located at position 0. Relocate it to memory location 2900.
                  0:       LOD   1000          2900:    LOD   3900
                  1:       ADD   1001          2901:    ADD   3901
                  2:       SUB   1002          2902:    SUB   3902
                  3:       STD   1003          2903:    STD   3903
                  4:       LOD   1100          2904:    LOD   4000
                  5:       SHL                 2905:    SHL
                  6:       SHL                 2906:    SHL
                  7:       ADD   1003          2907:    ADD   3903
                  8:       STD   1000          2908:    STD   3900
                  9:     (gap)
                             (don't change any data!!!!)
                  1000:    NUM   47            3900:    NUM   47
                  1001:    NUM   3             3901:    NUM   3
                  1002:    NUM   149           3902:    NUM   149
                  1003:    NUM   0             3903:    NUM   0
                  ...                          ...
                  1100:    NUM   99            4000:    NUM   99