Skip to content

Create a HACK program Div.asm

1 min read

Create a HACK program Div.asm that performs integer (Euclidean) division (see hereLinks to an external site. and hereLinks to an external site. for explanations and examples). Your program should divide the dividend stored in R0 by the divisor stored in R1 and put the quotient in R2 and the remainder in R3. If an exception division condition is encountered, then R2 (quotient) should be set to 0 and R3 (remainder) should be set to -1 if a non-zero divide by 0 is encountered or to -2 if 0 divide by 0 (NaN) is encountered. Your program should assume input registers R0 (dividend) and R1 (divisor) have already been loaded with values and should not modify them. For readability, your program should use the following self-explanatory variables which will need to be either loaded from the input registers R0 (dividend) and R1 (divisor) or copied into the output registers R2 (quotient) and R3 (remainder): dividend, divisor, quotient, and remainder.
Below is some pseudocode you may use to develop your program (note that the switch construct is used for clarity and the numbers in parentheses beside the cases could be convenient in the Hack language for identifying those cases).

PAYE Tax Calculator

Popular Posts
01
Indemnity Insurance: Providers and Types

Indemnity Insurance: Providers and Types

Getting Started
02
Casual Employment Contract Template for Kenya

Casual Employment Contract Template for Kenya

Getting Started
03
5 Reasons Why You Should Visit the Cayman Islands

5 Reasons Why You Should Visit the Cayman Islands

Getting Started
04
Top 3-Month Crops in Kenya: Profit Potential and Requirements

Top 3-Month Crops in Kenya: Profit Potential and Requirements

Getting Started
05
The Ultimate Tour Guide to Nairobi Hotels

The Ultimate Tour Guide to Nairobi Hotels

Getting Started
06
The Solution for Lifestyle Diseases Lies in Our Diet and Habit Choices

The Solution for Lifestyle Diseases Lies in Our Diet and Habit Choices

Getting Started