NAND2Tetris / CPU Emulator ROM @o 1 @o 2 @o 3 @o J @o @o 6 7 2 2 2 Screen CL Addr ว asm RAM CL Addr 2 dec▾ 0 0 1 0 2 0 3 0 4 0 5 0 คด Test: Default Edit ► Slow Test Script Compare File Output File Diff Table 1 repeat { 2 ticktock; 3 } 9 7 8 о 0 K Slow fx Fast x0 x1 x2 0 0 Enable Keyboard Key: Char code: 0 A Fast

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter13: File Input And Output
Section: Chapter Questions
Problem 16RQ
icon
Related questions
Question

I cant figure out how to run the following code on CPU Emulator of Nand2Tetris, please help

this is the code I want to run and see the output:

 

// R0: dividend
// R1: divisor
// R2: quotient
// R3: remainder

// Initialize registers
@0
D=M       // D = dividend (R0)
@R2
M=0       // R2 = quotient = 0
@R3
M=D       // R3 = remainder = dividend (R0)

// Check if divisor is 0 (to avoid division by zero)
@R1
D=M       // D = divisor (R1)
@DIVIDE
D;JEQ     // If divisor is 0, jump to END

@LOOP
@R1
D=M       // D = divisor (R1)
@R3
D=D-M     // D = remainder - divisor
@CHECK     // Check if remainder is still non-negative
D;JGE     // If D >= 0, continue with subtraction

// If remainder < divisor, we've found the quotient
@END
0;JMP     // Jump to END

@R2
M=M+1     // Increment quotient (R2)

@R3
D=M       // D = remainder
@R1
D=D-M     // D = remainder - divisor
@R3
M=D       // Update remainder (R3)

@LOOP     // Repeat the loop
0;JMP

// End of program
(END)
@END
0;JMP   // Infinite loop to end program (or you can implement a HALT)

NAND2Tetris / CPU Emulator
ROM
@o
1
@o
2 @o
3 @o
J
@o
@o
6
7
2 2 2
Screen
CL Addr
ว
asm
RAM
CL Addr 2 dec▾
0
0
1
0
2
0
3
0
4
0
5
0
คด
Test: Default Edit
►
Slow
Test Script Compare File Output File Diff Table
1 repeat {
2 ticktock;
3 }
9
7
8
о
0
K
Slow
fx
Fast
x0 x1 x2
0
0
Enable Keyboard
Key:
Char code: 0
A
Fast
Transcribed Image Text:NAND2Tetris / CPU Emulator ROM @o 1 @o 2 @o 3 @o J @o @o 6 7 2 2 2 Screen CL Addr ว asm RAM CL Addr 2 dec▾ 0 0 1 0 2 0 3 0 4 0 5 0 คด Test: Default Edit ► Slow Test Script Compare File Output File Diff Table 1 repeat { 2 ticktock; 3 } 9 7 8 о 0 K Slow fx Fast x0 x1 x2 0 0 Enable Keyboard Key: Char code: 0 A Fast
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning