Project 04, leider war Fill nicht meins
This commit is contained in:
41
projects/04/abgabe/Mult.asm
Normal file
41
projects/04/abgabe/Mult.asm
Normal file
@@ -0,0 +1,41 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/04/Mult.asm
|
||||
|
||||
// Multiplies R0 and R1 and stores the result in R2.
|
||||
// (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2], respectively.)
|
||||
//
|
||||
// This program only needs to handle arguments that satisfy
|
||||
// R0 >= 0, R1 >= 0, and R0*R1 < 32768.
|
||||
|
||||
@R2 //Ergebnisspeicher
|
||||
M=0 //init
|
||||
|
||||
@R1 //R1 dieser Wert dient als Schleifencounter
|
||||
D=M //Inhalt nach M
|
||||
|
||||
@i //Zähler
|
||||
M=D //i bekommt R1-Wert
|
||||
|
||||
@END
|
||||
D;JEQ
|
||||
|
||||
(LOOP)
|
||||
@R0 //R0 ansprechen
|
||||
D=M //Wert aus R0 in Datenspeicher
|
||||
|
||||
@R2 //Ergebnisspeicher
|
||||
M=D+M //Ergebnisspeicher = Datenspeicher + Ergebnisspeicher
|
||||
|
||||
@i //Zähler
|
||||
D=M //D=Zähler
|
||||
D=D-1 //D-1
|
||||
M=D //Zurückschreiben in Zähler
|
||||
|
||||
@LOOP //LOOP
|
||||
D;JGT //D GRÖSSER
|
||||
|
||||
(END) //END LOOP
|
||||
@END
|
||||
0;JMP
|
||||
Reference in New Issue
Block a user