@R2
M=0
@R0
D=M
@END
D, JEQ
@store
M=D
(LOOP)
@R1
D=D-M
@REMAINDER
D, JLT
@EVENLY
D, JEQ
@LOOP
0, JMP
(REMAINDER)
@R1
D=D+M
@R2
M=D
(EVENLY)
@store
D=M
@R0
M=D
(END)
@END
0, JMP
mod(x,y) works for unsigned integers, but not for signed integers in nand2tetris. What changes should I make?
167 Views Asked by comp sci At
1
There are 1 best solutions below
Related Questions in ASSEMBLY
- Is there some way to use printf to print a horizontal list of decrementing hex digits in NASM assembly on Linux
- How to call a C language function from x86 assembly code?
- Binary Bomb Phase 2 - Decoding Assembly
- AVR Assembly Clock Cycle
- Understanding the differences between mov and lea instructions in x86 assembly
- ARM Assembly code is not executing in Vitis IDE
- Which version of ARM does the M1 chip run on?
- Why would %rbp not be equal to the value of %rsp, which is 0x28?
- Move immediate 8-bit value into RSI, RDI, RSP or RBP
- Unable to run get .exe file from assembly NASM
- DOSbox automatically freezes and crashes without any prompt warnings
- Load function written in amd64 assembly into memory and call it
- link.exe unresolved external symbol _mainCRTStartup
- x86 Wrote a boot loader that prints a message to the screen but the characters are completely different to what I expected
- running an imf file using dosbox in parallel to a game
Related Questions in UNSIGNED-INTEGER
- Creating C++ templates with a value switch based on typename
- 64 unsigned integers in Lua 5.3/5.4 do not behave like in "Programming in Lua"
- How would I store multiple numbers in a UInt16Array or UInt32Array?
- How to loop over 0 .. v.len() - 1 when v might be empty?
- Safe countdown loop
- Emulating signed integers using unsigned integers in C
- How to calculate the absolute difference of two unsigned integers?
- Why is the expected output not displayed
- What happens when you pass a signed integer to a function that expects an unsigned integer for the purpose of filtering/mixing?
- Is this bitwise conversion safe?
- What are the 5bits and the 6bits in when bit shifting by the size of the integer?
- Fixed Point Binary Multiplication Over Flow Problem
- An unsigned int literal outside bounds
- Branchless way to add two UINT while avoiding overflow?
- Extract from array to integer
Related Questions in MODULO
- Mod operator returning wrong output
- Dispatch metadata from WordPress DB query into a table with 4 columns
- Why don't x86-64 (or other architectures) implement division by 10?
- Best way to set desired range with inverse trig functions?
- Why two modular operations cannot be optimized as well as one modular operation
- How to sort lists of matrices and find the index of a matrix on a list?
- Google Sheets - Why are there garbage digits in MOD(??)&"*"?
- How to write c language modulo 2 with use mpfr function?
- Python how to convert total teaspoons to tablespoons, ounces, cups, and pints using modulus and floor division
- How to evaluate an expression in SageMath over Zmod?
- Alternate show of every 3 then every 1 item
- swap group of characters every words in list
- JS Last value in array is never checked when looped
- Save data every t time units in R
- Julia modulo of vector (or remainer of vector)
Related Questions in NAND2TETRIS
- Nand2tetris Project 9 out of segment space
- How do I modify this .hdl chip to fulfill the question's requirements? (boolean logic / nand2tetris)
- Nand2Tetris Not16.hdl
- Logic Gate Advice - Rearranging bits and anticipating the outcome
- Nand2Tetris CPU containing PC gate: not sure what to do with PC gate output[15] single bit since CPU PC out requires just [0..14]
- Stuck with the nand2tetris VMtranslator optimization
- Nand2tetris Mult.hack doesn't exist
- How to create a Bitwise Nand of memory cell 0 and 1, result recorded in memory cell 2
- Creating new string somehow changing value of old string? | C
- Nand2Tetris Weird screen behavior
- nand2Tetris use of chips as blocks
- How to build a 8 bit wide hdl ALU
- I am trying to build a PC CHIP, but am getting the error message, Line 19, out(8) and out(16) have different bus widths
- Data loss when transferring data on one line use Mux/ DMux
- Syntax error when implementing a Mux gate in Nand2Tetris
Related Questions in SIGNED-INTEGER
- Why is the expected output not displayed
- How to derive correct result when overflow occurs in 2's Complement Addition?
- subtraction of 2 sign and magnitude binary numbers in assembly (ex : 11110110 and 10101011)
- Questions about C strlen function
- Bit shifting signed and unsigned integers
- Idiomatically convert signed to unsigned types if you know that value will be positive
- How to subtract negative numbers from negative numbers using Complement notation?
- Doing calculation in the range 0f 10^30
- Why, in some C++ compilers, does `int x = 2147483647+1;` give only a warning but stores a negative value, while some compilers give a runtime error?
- About int and unsigned int
- C usual arithmetic conversions rules
- Why do `(char)~0` and `(unsigned char)~0` return values of different widths?
- Converting unsigned to signed integers (Using Excel formulas or Power Query)
- How does sign contraction work from 16 bit to 8 bit?
- How to access Json element with the name "long" and "short"
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You should identify the conditions under which your current code works, and fails. Does it require both operands to be positive, or just have the same sign?
Once you have done that, you also know the conditions under which it fails. You can then check for those, and either execute different code under those conditions, or modify the operands so that the current code works and generates the proper result.
To get you started, here's some examples of what modulo should return. Good luck!