1.- In this assignment you will implement a simulation of the interaction of use
ID: 3812978 • Letter: 1
Question
1.- In this assignment you will implement a simulation of the interaction of user programswith the OS to execute an I/O operation on two different devices. User programs:User programs will communicate with DOIO (OS) to request an I/O operation. (This willsimulate a system call)
User programs will give to DOIO three parameters: User id, device number (dev is arandom number in the range 1 and 2 that represents device one or device two) and anaddress (addr is a random number in the range 1 and 20.) (addr is an integer thatrepresents a track number in the hard drive).
User programs will pass the parameters to DOIO through three buffers of size one each(bufid, bufdev, and bufaddr).
Once the parameters are stored in the buffers, user programs executes a p(request_served)operation to wait for the completion of the I/O operation. You will need a semaphore arrayrequest_served[5].
There will be five users running concurrently and each will execute 5 I/O operations. DOIO:
DOIO will collect and id, device(dev), and address(addr) from bufid, bufdev, andbufaddr to assemble the IORB.
DOIO will check on device number to decide which one of the two devices will get theIORB.
Once the device has been selected, DOIO will store the IORB (id and addr) into the twobuffers that represent the IORQ (iorqid and iorqaddr) of the selected device. Notice thatyou need separate buffers (one for each device). Device drivers (1 and 2):Device drivers will collect an IORB (made up of id and addr) from iorqid and iorqaddr
and then initiate the physical I/O operation on the hard drive it controls and wait for the I/Ooperation to be completed: p(operation_complete).
The device driver initiates the physical I/O operation by storing addr into a buffer of lengthone. The buffer name is “pio” (physical I/O).
When the I/O operation completes a signal is received, the Device driver will identify theUser that issued the I/O request using the id, and will signal the semaphore“request_served” associated to the User.
Disk (1 and 2):
The Disk processes simulates the access to a track in the hard drive.
The Disk process gets the addr from pio and stores it in a variable called “seek” and
iterates in a dummy loop from 1 to “seek”.Once out of the loop, disk will execute a v on the semaphore “operation_complete” a) Define all semaphores that you need according to the number of buffers used.b) Each user will make 5 system calls to initiate I/O operationsc) DOIO will create 25 IORBd) The sum of the I/O operations executed by drivers must add up 25. You will need a
shared variable to control the total number of I/O operations because it is not knownbefore hand the numbers of I/O operations initiated by each Device driver. Project Direction You will write the program C-- based on the BACI interpreter that you used in programming project 1. 1.- In this assignment you will implement a simulation of the interaction of user programswith the OS to execute an I/O operation on two different devices. User programs:
User programs will communicate with DOIO (OS) to request an I/O operation. (This willsimulate a system call)
User programs will give to DOIO three parameters: User id, device number (dev is arandom number in the range 1 and 2 that represents device one or device two) and anaddress (addr is a random number in the range 1 and 20.) (addr is an integer thatrepresents a track number in the hard drive).
User programs will pass the parameters to DOIO through three buffers of size one each(bufid, bufdev, and bufaddr).
Once the parameters are stored in the buffers, user programs executes a p(request_served)operation to wait for the completion of the I/O operation. You will need a semaphore arrayrequest_served[5].
There will be five users running concurrently and each will execute 5 I/O operations. DOIO:
DOIO will collect and id, device(dev), and address(addr) from bufid, bufdev, andbufaddr to assemble the IORB.
DOIO will check on device number to decide which one of the two devices will get theIORB.
Once the device has been selected, DOIO will store the IORB (id and addr) into the twobuffers that represent the IORQ (iorqid and iorqaddr) of the selected device. Notice thatyou need separate buffers (one for each device). Device drivers (1 and 2):Device drivers will collect an IORB (made up of id and addr) from iorqid and iorqaddr
and then initiate the physical I/O operation on the hard drive it controls and wait for the I/Ooperation to be completed: p(operation_complete).
The device driver initiates the physical I/O operation by storing addr into a buffer of lengthone. The buffer name is “pio” (physical I/O).
When the I/O operation completes a signal is received, the Device driver will identify theUser that issued the I/O request using the id, and will signal the semaphore“request_served” associated to the User.
Disk (1 and 2):
The Disk processes simulates the access to a track in the hard drive.
The Disk process gets the addr from pio and stores it in a variable called “seek” and
iterates in a dummy loop from 1 to “seek”.Once out of the loop, disk will execute a v on the semaphore “operation_complete” a) Define all semaphores that you need according to the number of buffers used.b) Each user will make 5 system calls to initiate I/O operationsc) DOIO will create 25 IORBd) The sum of the I/O operations executed by drivers must add up 25. You will need a
shared variable to control the total number of I/O operations because it is not knownbefore hand the numbers of I/O operations initiated by each Device driver. Project Direction You will write the program C-- based on the BACI interpreter that you used in programming project 1.
Explanation / Answer
.data
# const string for welcome
welc: .asciiz "Welcome to SPIM Calculator one.0! "
p_int: .asciiz " Please provide associate integer: "
p_op: .asciiz " Please provide associate operator: "
i_err: .asciiz " Input Incorrect, unhealthy operator! "
again_str: .asciiz "Another calculation? (y/n)"
rmndr: .asciiz " r: "
new_line: .asciiz " "
int1: .word one # house to carry int one
int2: .word one # house to carry int two
raw_in: .space one # house to carry raw input
op: .space one # house to carry operator char
a_char: .space one # house to carry once more char
out: .word one # house to carry output
remain: .word one # house to carry remainder
#operator constants
c_plus: .ascii "+" # const for +
c_min: .asciiz "-" # const for -
c_mult: .asciiz "*" # const for *
c_divi: .asciiz "/" # const for /
c_eq: .asciiz "=" # const for =
c_no: .asciiz "n" # const for n
.text
.globl main
main: li $v0, four # syscall four, print string
la $a0, welc # provide argument: string
syscall # really print string
calc: la $t6, stay # load remainder variable
move $t6, $zero # store zero in remainder (reset)
li $v0, four # syscall four, print string
la $a0, purpose # provide argument: string
syscall # really print string
li $v0, five # tell syscall we would like to scan int one
syscall # really scan in int one
la $s1, int1 # load int1 into $s1
move $s1, $v0 # copy the number from $v0 to int1
li $v0, four # syscall four, print string
la $a0, purpose # provide argument: string
syscall # really print string
li $v0, five # tell syscall we would like to scan int two
syscall # really scan in int two
la $s2, int2 # provide $s2 the address to carry int two
move $s2, $v0 # copy the number from $v0 to $s2
li $v0, four # syscall four, print string
la $a0, p_op # provide argument: string
syscall # really print string
li $v0, eight # tell syscall we would like to scan operator
la $a0, op # provide $a0 the address to carry the operator
syscall # really scan in operator
lb $t0, op # load the primary computer memory unit of op
li $t1, '+' # load const for and
li $t2, '-' # load const for minus
li $t3, '*' # load const for multiplying
li $t4, '/' # load const for dividing
la $s0, out # load intent on $s0
beq $t0, $t1, and # we're adding
beq $t0, $t2, minus # we're subtracting
beq $t0, $t3, multi # we're multiplying
beq $t0, $t4, divi # we're dividing
# else
j error # incorrect input
plus: add $s0, $s1, $s2 # add our ints, store in $t0
j print
minus: sub $s0, $s1, $s2 # cypher our ints, store in $t0
j print
multi: slt $t1, $t2, $s2 # if our counter is a smaller amount than int2, set $t1 to one
beq $t1, $zero, print # if we've reached int2, we're done
add $s0, $s1, $s1 # add int1 and int1, store in out
j multi # loop
divi: la $t0 stay # load remainder into $t0
move $t0, $s1 # set remainder to dividend
add $s0, $zero, $zero # embarked on to zero, simply just in case
loop: slt $t1, $t0, $s2 # if remainder is a smaller amount than divisor, set 1
beq $t1, $zero, print # if we're done branch to done
sub $t0, $t0, $s2 # sub divisor from remainder, store in remainder
addi $s0, $s0, one # increment quotient by one
j loop # loop
print: li $v0, one # tell syscall we would like to print int
la $a0, int1 # provide syscall int1 to print
syscall # really print int
li $v0, four # tell syscall we would like to print string
lb $a0, op # tell syscall we would like to print operator
syscall # really print string
li $v0, one # tell syscall we would like to print int
la $a0, int2 # provide syscall int2 to print
syscall # really print int
li $v0, four # tell syscall we would like to print string
la $a0, c_eq # tell syscall we would like to print operator
syscall # really print string
li $v0, one # tell syscall we would like to print number
la $a0, out # provide syscall our output
syscall # really print int
la $t0, stay # load remainder
beq $t0, $zero, once more # if we've no remainder, end printing
li $v0, four # tell syscall we would like to print string
la $a0, rmndr # tell syscall we would like to print remainder string
syscall # print "r: "
li $v0, one # tell syscall we would like to print int
la $a0, stay # provide syscall our remainder to print
syscall # print remainder
again: li $v0, four # tell syscall we would like to print string
la $a0, printing operation # tell syscall to print printing operation
syscall
la $a0, once more_str # load prompt for again string for syscall
syscall
li $v0, eight # tell syscall we would like to scan string
la $a0, a_char # tell syscall to place it in $a0
syscall
lb $t0, a_char
li $t1, 'n' # get n char thus we will compare
beq $t0, $t1, exit # if we tend to ar done, exit
#else loop
j calc # jump to starting
error: li $v0, four # tell syscall we would like to print string
la $a0, i_err # provide syscall what to print
syscall # really print
j once more # move to prompt for try
exit: li $v0, ten # exit code
syscall #exit!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.