-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🚀 Concat of String and If instruction
- Loading branch information
1 parent
64715d4
commit 7cef1dc
Showing
5 changed files
with
228 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { registers as r } from "./constants.js" | ||
import { Generador } from "./generator.js" | ||
|
||
/** | ||
* @param {Generador} code | ||
*/ | ||
export const concatString = (code) => { | ||
// A0 -> dirección en heap de la primera cadena | ||
// A1 -> dirección en heap de la segunda cadena | ||
// result -> push en el stack la dirección en heap de la cadena concatenada | ||
|
||
code.comment('Guardando en el stack la dirección en heap de la cadena concatenada') | ||
code.push(r.HP); | ||
|
||
code.comment('Copiando la 1er cadena en el heap') | ||
const end1 = code.getLabel() | ||
const loop1 = code.addLabel() | ||
|
||
code.lb(r.T1, r.A0) | ||
code.beq(r.T1, r.ZERO, end1) | ||
code.sb(r.T1, r.HP) | ||
code.addi(r.HP, r.HP, 1) | ||
code.addi(r.A0, r.A0, 1) | ||
code.j(loop1) | ||
code.addLabel(end1) | ||
|
||
code.comment('Copiando la 2da cadena en el heap') | ||
const end2 = code.getLabel() | ||
const loop2 = code.addLabel() | ||
|
||
code.lb(r.T1, r.A1) | ||
code.beq(r.T1, r.ZERO, end2) | ||
code.sb(r.T1, r.HP) | ||
code.addi(r.HP, r.HP, 1) | ||
code.addi(r.A1, r.A1, 1) | ||
code.j(loop2) | ||
code.addLabel(end2) | ||
|
||
code.comment('Agregando el caracter nulo al final') | ||
code.sb(r.ZERO, r.HP) | ||
code.addi(r.HP, r.HP, 1) | ||
} | ||
|
||
export const builtins = { | ||
concatString: concatString | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters