Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

OS Problem Set Introduction The following machine description will provide the b

ID: 670827 • Letter: O

Question

OS Problem Set

Introduction

The following machine description will provide the basis for this assignment. You will create a virtual machine/operating system for the machine described below that will accept programs in the target machine language. The details for this assignment are presented below following the machine description.

MICROPROGRAMMING/MACHINE DISCRIPTION

The following is a description of a machine called SIMMAC that contains the following: 512 32-bit words of memory (memory is word addressable).
Each Instruction consists of a 16-bit opcode and a 16-bit operand.
An ALU for performing mathematical operations.

Registers

ACC Accumulator; A 32-bit register involved in all arithmetic operations. One of the operands in each arithmetic operation must be in the Accumulator; the other must be in primary storage.

PSIAR Primary Storage Instruction Address Register; This 16-bit register points to the location in primary storage of the next machine language instruction to be executed.

SAR Storage Address Register; This 16-bit register is involved in all references to primary storage. It holds the address of the location in primary storage being read from or written to.

SDR Storage Data Register; This 32-bit register is also involved in all references to primary storage. It holds the data being written to or receives the data being read from primary storage at the location specified in the SAR.

TMPR Temporary Register; This 32-bit register is used to extract the address portion (rightmost 16-bits) of the machine instruction in the SDR so that it may be placed in the SAR. (No SDR to SAR transfer.)

CSIAR Control Storage Instruction Address Register; This register points to the location of the next micro-instruction (in control storage) to be executed.

IR Instruction Register; This register contains the current instruction being executed.

MIR Micro-instruction Register; This register contains the current micro-instruction being executed.

Register Transfers (REG is ACC, PSIAR, or TMPR):

SDR = REG REG = SDR SAR = REG

Primary Storage Operations:

READ Data from primary storage location named in the SAR is placed in the SDR.

WRITE Data in the SDR is placed in primary storage location named in the SAR.

Sequencing operations:

CSIAR = CSIAR + 1
CSIAR = decoded SDR
CSIAR = constant
SKIP = (add 2 to CSIAR if ACC=0; else add 1)

Operations involving the accumulator:

ACC = ACC + REG ACC = ACC - REG ACC = REG
REG = ACC

ACC = REG + 1 Instruction fetch:

(00) SAR = PSIAR

(01) READ

(02) IR = SDR

(03) SDR = decoded IR (Operand)

(04) CSIAR = decoded IR (OP CODE)

ADD (Opcode 10):

(10) TMPR = ACC
(11) ACC = PSIAR + 1 (12) PSIAR = ACC
(13) ACC = TMPR
(14) TMPR = SDR
(15) SAR = TMPR
(16) READ
(17) TMPR = SDR
(18) ACC = ACC + TMPR (19) CSIAR = 0

SUB (Opcode 20):

(20) TMPR = ACC
(21) ACC = PSIAR + 1 (22) PSIAR = ACC
(23) ACC = TMPR
(24) TMPR = SDR
(25) SAR = TMPR
(26) READ
(27) TMPR = SDR
(28) ACC = ACC - TMPR (29) CSIAR = 0

LOAD (LDA, Opcode 30):

(30) TMPR = ACC (31) ACC = PSIAR + 1 (32) PSIAR = ACC (33) ACC = TMPR (34) TMPR = SDR (35) SAR = TMPR (36) READ
(37) ACC = SDR
(38) CSIAR = 0

STORE (Name STR, Opcode 40):

(40) TMPR = ACC (41) ACC = PSIAR + 1 (42) PSIAR = ACC (43) ACC = TMPR (44) TMPR = SDR (45) SAR = TMPR (46) SDR = ACC
(47) WRITE
(48) CSIAR = 0

BRANCH (Name BRH, Opcode 50):

(50) PSIAR = SDR (51) CSIAR = 0

COND BRANCH (Name CBR, Opcode 60):

(60) SKIP
(61) CSIAR = 64
(62) PSIAR = SDR (63) CSIAR = 0
(64) TMPR = ACC (65) ACC = PSIAR + 1 (65) PSIAR = ACC (66) ACC = TMPR (67) CSIAR = 0

LOAD IMMEDIATE (LDI, Opcode 70):

(70) TMPR = ACC (71) ACC = PSIAR + 1 (72) PSIAR = ACC (73) ACC = TMPR (74) ACC = SDR
(75) CSIAR = 0

SIMMAC Programming Language Description

Addition
Usage: ADD

Where

holds the value to add to the accumulator.

Subtraction
Usage: SUB

Where

holds the value to subtract from the accumulator.

Load
Usage: LDA

Where

holds the value to load in to the accumulator.

Load Immediate
Usage: LDI number

Where number is the value to load in to the accumulator.

Store
Usage: STR

Where

is the storage location for the contents of the accumulator.

Branch
Usage: BRH

Where

is the target of the absolute branch.

Conditional Branch
Usage: CBR

Where

is the target of an absolute branch if the accumulator is zero.

Project Description

Design and implement a program to simulate the operation of the SIMMAC based on the descriptions above.

Add a HALT instruction that dumps the contents of all registers and memory and then prints an “End of Job” message.

Your project must implement multi-tasking in a single queue using a round-robin scheduling discipline. You will implement process entities (jobs) that will allow your machine to run several SIMMAC machine-language programs. In order to do this you will define a Process Control Block (PCB) data structure that will be created for each job in your system. For this assignment assume each SIMMAC instruction is equivalent to one clock cycle. Additionally the time quantum value for round-robin scheduling is an integer multiple of a clock cycle. The quantum value is to be set on the command line or prompted for during initialization.

You will define the notion of an interrupt handler that will process a time quantum for each running job. On each job switch, you will print some state information such as which job will be loaded and the current state of the job queues.

Your version of SIMMAC will then run multiple SIMMAC machine language programs simultaneously. These programs will test the ability of your SIMMAC to handle multi- tasking and scheduling. You must design your system such that all SIMMAC machine programs are loaded from text files.

The SIMMAC must be designed to take command line arguments or to prompt for input files in addition to the previously specified items. By this mechanism, all SIMMAC language programs will be loaded. Since there is the LDI command, all data can be loaded into SIMMAC memory using SIMMAC programming statements.

You must develop the following SIMMAC language programs to be run on your SIMMAC machine:

1) Write three programs in the machine language of the SIMMAC that will total the numbers stored in 20 different locations and place the result in a single location.

2) Write a program in the machine language of the SIMMAC that will decrement the value stored in location 201 (must be at least 100) by one until the result is zero. Store the result in location 202.

3) Write a program in the machine language of the SIMMAC that will increment the value stored in location 301 by two until the value has been increased by 200. Store the result in location 302.

Each line of any SIMMAC program must have the following format:

Opcode Operand

You will be responsible for turning in the system design document, source code of your version of SIMMAC (this code must be appropriately commented & readable), an executable version of your SIMMAC, and the output generated from your SIMMAC programs running on your version of SIMMAC. These items are to be placed in ZIP format and submitted to the OS Problem Set Assignment in Blackboard Assignments.

Explanation / Answer

    .Ltext0:
                    .globl   offset
                    .data
                    .align 4
                offset:
0000 28000000        .long   40
                    .comm   array1,80,32
                    .comm   array2,80,32
                    .comm   num,4,4
                    .comm   array3,240,32
                    .comm   a,4,4
                    .comm   b,4,4
                    .globl   c
                    .bss
                    .align 4
                c:
0000 00000000        .zero   4
                    .globl   average
                    .align 4
                average:
0004 00000000        .zero   4
                    .comm   p,4,4
                    .comm   q,4,4
                    .comm   data1,4,4
                    .section   .rodata
                    .align 8
                .LC0:
0000 0A202074        .string   " total the numbers in 20 locations "
     6F74616C
     20746865
     206E756D
     62657273
                    .text
                    .globl   func20Loc
                func20Loc:
                .LFB0:
                    .cfi_startproc
0000 55              pushq   %rbp
                    .cfi_def_cfa_offset 16
                    .cfi_offset 6, -16
0001 4889E5         movq   %rsp, %rbp
                    .cfi_def_cfa_register 6
0004 4883EC10        subq   $16, %rsp
0008 BF000000        movl   $.LC0, %edi
     00
000d B8000000        movl   $0, %eax
     00
0012 E8000000        call   printf
     00
                .LBB2:
0017 C745FC01        movl   $1, -4(%rbp)
     000000
001e EB30            jmp   .L2
                .L3:
0047 8B050000        movl   offset(%rip), %eax
     0000
004d 0145FC         addl   %eax, -4(%rbp)
0020 8B45FC         movl   -4(%rbp), %eax
0023 4898            cltq
0025 8B148500        movl   array3(,%rax,4), %edx
     000000
002c 8B050000        movl   offset(%rip), %eax
     0000
0032 0FAF45FC        imull   -4(%rbp), %eax
0036 83C014         addl   $20, %eax
0039 01C2            addl   %eax, %edx
003b 8B45FC         movl   -4(%rbp), %eax
003e 4898            cltq
0040 89148500        movl   %edx, array3(,%rax,4)
     000000
                .L2:
0050 8B050000        movl   offset(%rip), %eax
     0000
0056 83C014         addl   $20, %eax
0059 3B45FC         cmpl   -4(%rbp), %eax
005c 7DC2            jge   .L3
                .LBE2:
005e C9              leave
                    .cfi_def_cfa 7, 8
005f C3              ret
                    .cfi_endproc
                .LFE0:
                    .section   .rodata
0026 0000            .align 8
                .LC1:
0028 0A202064        .string   " decrement value in location 201 "
     65637265
     6D656E74
     2076616C
     75652069
                    .text
                    .globl   funcDecr201
                funcDecr201:
                .LFB1:
                    .cfi_startproc
0060 55              pushq   %rbp
                    .cfi_def_cfa_offset 16
                    .cfi_offset 6, -16
0061 4889E5         movq   %rsp, %rbp
                    .cfi_def_cfa_register 6
0064 4883EC10        subq   $16, %rsp
0068 BF000000        movl   $.LC1, %edi
     00
006d B8000000        movl   $0, %eax
     00
0072 E8000000        call   printf
     00
                .LBB3:
0077 C745FC01        movl   $1, -4(%rbp)
     000000
007e EB36            jmp   .L5
                .L6:
00ad 8B050000        movl   offset(%rip), %eax
     0000
00b3 0145FC         addl   %eax, -4(%rbp)
0080 8B45FC         movl   -4(%rbp), %eax
0083 4898            cltq
0085 8B148500        movl   array1(,%rax,4), %edx
     000000
008c 8B050000        movl   offset(%rip), %eax
     0000
0092 0FAF45FC        imull   -4(%rbp), %eax
0096 B937FFFF        movl   $-201, %ecx
     FF
009b 29C1            subl   %eax, %ecx
009d 89C8            movl   %ecx, %eax
009f 01C2            addl   %eax, %edx
00a1 8B45FC         movl   -4(%rbp), %eax
00a4 4898            cltq
00a6 89148500        movl   %edx, array1(,%rax,4)
     000000
                .L5:
00b6 8B050000        movl   offset(%rip), %eax
     0000
00bc 05C90000        addl   $201, %eax
     00
00c1 3B45FC         cmpl   -4(%rbp), %eax
00c4 7DBA            jge   .L6
                .LBE3:
00c6 C9              leave
                    .cfi_def_cfa 7, 8
00c7 C3              ret
                    .cfi_endproc
                .LFE1:
                    .section   .rodata
004c 00000000        .align 8
                .LC2:
0050 0A20496E        .string   " Increment value at location 301 "
     6372656D
     656E7420
     76616C75
     65206174
                    .text
                    .globl   funcIncr301
                funcIncr301:
                .LFB2:
                    .cfi_startproc
00c8 55              pushq   %rbp
                    .cfi_def_cfa_offset 16
                    .cfi_offset 6, -16
00c9 4889E5         movq   %rsp, %rbp
                    .cfi_def_cfa_register 6
00cc 4883EC10        subq   $16, %rsp
00d0 BF000000        movl   $.LC2, %edi
     00
00d5 B8000000        movl   $0, %eax
     00
00da E8000000        call   printf
     00
                .LBB4:
00df C745FC01        movl   $1, -4(%rbp)
     000000
00e6 EB32            jmp   .L8
                .L9:
0111 8B050000        movl   offset(%rip), %eax
     0000
0117 0145FC         addl   %eax, -4(%rbp)
00e8 8B45FC         movl   -4(%rbp), %eax
00eb 4898            cltq
00ed 8B148500        movl   array2(,%rax,4), %edx
     000000
00f4 8B050000        movl   offset(%rip), %eax
     0000
00fa 0FAF45FC        imull   -4(%rbp), %eax
00fe 052D0100        addl   $301, %eax
     00
0103 01C2            addl   %eax, %edx
0105 8B45FC         movl   -4(%rbp), %eax
0108 4898            cltq
010a 89148500        movl   %edx, array2(,%rax,4)
     000000
                .L8:
011a 8B050000        movl   offset(%rip), %eax
     0000
0120 052D0100        addl   $301, %eax
     00
0125 3B45FC         cmpl   -4(%rbp), %eax
0128 7DBE            jge   .L9
                .LBE4:
012a C9              leave
                    .cfi_def_cfa 7, 8
012b C3              ret
                    .cfi_endproc
                .LFE2:
                    .section   .rodata
                .LC3:
0073 0A205349        .string   " SIMMAC Simulation"
     4D4D4143
     2053696D
     756C6174
     696F6E00
                    .text
                    .globl   main
                main:
                .LFB3:
                    .cfi_startproc
012c 55              pushq   %rbp
                    .cfi_def_cfa_offset 16
                    .cfi_offset 6, -16
012d 4889E5         movq   %rsp, %rbp
                    .cfi_def_cfa_register 6
0130 BF000000        movl   $.LC3, %edi
     00
0135 B8000000        movl   $0, %eax
     00
013a E8000000        call   printf
     00
013f B8000000        movl   $0, %eax
     00
0144 5D              popq   %rbp
                    .cfi_def_cfa 7, 8
0145 C3              ret
                    .cfi_endproc
                .LFE3:
                .Letext0: