Enable contrast version

Tutor profile: Gaurav G.

Inactive
Gaurav G.
Professional Tutor with industry experience
Tutor Satisfaction Guarantee

Questions

Subject: MIPS

TutorMe
Question:

What are the Hazards in a pipelined processor and how can we handle them?

Inactive
Gaurav G.
Answer:

A pipelined processor is subjected to three types of hazards. First is structural hazard when more than one instruction is competing for the same hardware resource in the CPU. This can resolved by adding more function units that might lead to contention in the CPU. Second is control hazards that arise due to conditional branches. The program counter must be reloaded with target address leading to flushing of instructions already in the pipeline. Two schemes are used to overcome stalls due to these. One is delayed branching where condition branch is shifted by one instruction in program code allowing time to fetch target address. Another is use of branch predictors ( dynamic branch prediction using 3 bit prediction or Branch target address buffers) to predict branch outcome and reload PC accordingly. This scheme is widely used and helps save control hazards to great extent. Most prevalent hazard in pipeline is data hazard. This is implicit in code due to data dependence of subsequent instructions on results of current instruction under execution. This is resolved using data forwarding paths with in CPU that allow sharing of outcome before register write back is completed. There are other dependencies that are resolved using register renaming and instruction re-ordering.

Subject: Databases

TutorMe
Question:

At Spock Bank, loan repayments are made purely online by transferring fund from another account – typically a savings account -- to the loan account. The customers normally use the bank’s app or webpage and specify from which account they would want to make the repayment, and towards which loan this payment should count. This action of the customer will effectively call a stored procedure as: Repay_loan(from_BSB, from_accountNo, to_loan, amount) with relevant parameters, and make appropriate changes to the relevant tables. This procedure is intended to transfer the amount of money in question from the account identified by (from_BSB, from_accountNo) to the loan account associated with the to_loan.

Inactive
Gaurav G.
Answer:

-- SQL Procedure to achieve the required function CREATE DEFINER=`root`@`localhost` PROCEDURE `Repay_loan`( In from_BSB varchar(10), IN from_accountNo varchar(10), IN to_loan varchar(10), In amount decimal(8,0)) BEGIN DECLARE acctbal decimal(10,0); DECLARE accountnum varchar(10); DECLARE bsb varchar(10); DECLARE loanowner VARCHAR(10); DECLARE ownercount integer; SELECT loan_accountBSB into bsb FROM T_Loan WHERE LoanID = to_loan; SELECT loan_acctno into accountnum FROM T_Loan WHERE LoanID = to_loan; -- get the owner of the loan SELECT Customer_ID into loanowner from T_own where Account_No = accountnum AND Account_BSB = BSB; -- check if from_accountNo and from_BSB are associated to owner SELECT count(Customer_ID) into ownercount from T_own where Customer_ID = loanowner and Account_No = from_accountNo AND Account_BSB = from_BSB; -- if customer is associated with the payment account IF ownercount > 0 THEN -- make a transaction SELECT AccountBal INTO acctbal FROM T_Account WHERE AccountNo = from_accountNo AND BSB = from_BSB; SET acctbal = acctbal - amount; IF (acctbal > 0) THEN -- credit paying account UPDATE T_Account SET AccountBal = acctbal WHERE AccountNo = from_accountNo AND BSB = from_BSB; -- get loan account balance and update loan balance SELECT Loan_AcctNo INTO accountnum FROM T_Loan WHERE LoanID = to_loan; SELECT Loan_AccountBSB INTO bsb FROM T_Loan WHERE LoanID = to_loan; SELECT AccountBal INTO acctbal FROM T_Account WHERE AccountNo = accountnum AND BSB = bsb; -- assuming loan balances are in negative SET acctbal = acctbal + amount; UPDATE T_Account SET AccountBal = acctbal WHERE AccountNo = accountnum AND BSB = bsb; -- make en entry into repayment transaction INSERT INTO T_Repayment (Repayment_LoanID,RepaymentAmount, RepaymentDate) VALUES (to_loan, amount, DATE(NOW())); ELSE SELECT ('Bank Balance not sufficient to pay the loan amount'); END IF; ELSE -- message about failure SELECT ('Payment account not associated to the owner of the loan account'); END IF; END

Subject: Assembly Language

TutorMe
Question:

Read a 5 digit integer from user and divide the number by 3.3. Display the result of the division.

Inactive
Gaurav G.
Answer:

The program accepts the number from user using one of the read integer syscall functions and stores the number in a register. Since this is a floating point operation which is not directly supported by the MIPS processor. The coprocessor 1 is used along with the main core to perform the operation. The co-processor 1 is special hardware added to MIPS for floating point operations. The coprocessor has its own set of registers and instruction sets that are executed by main processor. The floating point numbers need a special type of representation unlike integer numbers which are written using weighted binary notation. The floating point numbers follow an IEEE format numbered IEEE-754. The numbers can be represented using 32 bits or 64 bits as per requirement of precision in decimal values and the scale of number to be calculated. The format used for the task is single precision format occupying 32 bits. Co-processor supports certain set of instructions that allow conversion of integers to floating points and vice-versa. The user input is received and shifted to co-processor where it is converted from simple integer to a floating point number. The constant 3.3 has a unique floating point presentation which is also shifted to the co-processor. The numbers are then used for division and result is obtained as another floating point number. Since MIPS cannot understand FP format, the number needs to be converted to 32 bit integer presentation before being shifted back to main processor. The main core then displays the result. MIPS CODE: .data Message1: .asciiz "Enter Student Number" Message2: .asciiz "New Number is: " .text la $a0, Message1 # load message offset in register li $v0, 4 # syscall argument to print syscall # print message la $v0, 5 # syscall argument to read integer syscall # read integer # Move the input integer to FP register # convert it to floating point # move the constant 3.3 to FP register using its IEEE-format value # divide the values # convert the quotient in result register to integer value # move the result to main processor # print the result mtc1 $v0,$f1 # input to dividend li $v0,0x40533333 # constant to divisor mtc1 $v0,$f3 cvt.s.w $f1,$f1 # convert input to floating point format div.s $f0,$f1,$f3 # divide input by 3.3 cvt.w.s $f0,$f0 # convert result to integer mfc1 $t0,$f0 # move result to processor la $a0, Message2 # load message offset in register li $v0, 4 # syscall argument to print syscall # print message move $a0,$t0 # load integer value in $a0 li $v0, 1 # syscall argument to print integer syscall # print integer li $v0, 10 # system call for termination syscall

Contact tutor

Send a message explaining your
needs and Gaurav will reply soon.
Contact Gaurav

Request lesson

Ready now? Request a lesson.
Start Lesson

FAQs

What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Lesson" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.