Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to remove white spaces at the end of a string in MARIE ASSEMBLY? I\'m trying

ID: 3743907 • Letter: H

Question

How to remove white spaces at the end of a string in MARIE ASSEMBLY?

I'm trying to trim the white spaces at the end of a string. I have a print subroutine that stops printing once it reaches a 0 character so to trim the string at the ends I iterate to the end of the string, get the address of the last character and iterate backwards replacing any white spaces.

My problem is HOW to replace the white spaces because if I replace it in my trim string address I can't iterate backwards correctly? Because it loads value from address 0 instead?

TrimStringAddr, HEX 0    / address of string to trim
TrimString,     HEX 0
/ <--- this is where you add your code for trimming a string
StartTrim,      LoadI TrimStringAddr
                Skipcond 800
                Jump getSecondLastChar//if character is 0, start iterating backwards
                Load TrimStringAddr
                Add One
                Store TrimStringAddr
                Jump StartTrim
               
//Remove spaces
Space, DEC 32 //constant needed for subroutine
CharacterReplace, Hex 000//constant for subroutine
//ShowOutput, Hex 0//to show output
//To get second last char
getSecondLastChar, Load TrimStringAddr
                   Subt One
                   Store TrimStringAddr
                   Jump StartRemoveSpace


StartRemoveSpace, LoadI TrimStringAddr//get last char that's not zero
                  Subt Space
                  Skipcond 400//if its a space skip next line
                  JumpI TrimString//terminate trimming
                  Load CharacterReplace//replace with 0

//PROBLEM HERE
                 //Replace where??
                  //Store TrimStringAddr

                  Load TrimStringAddr
                  Subt One// iterate backwards
                  Store TrimStringAddr
                  Jump StartRemoveSpace

Explanation / Answer

python code :

->In python, to reverse the string we use string slicing, in string slicing the procedure is string[start:end:s teps] to reverse the string use string[::-1]

-> After reversing apply whitespace removing function i.e. replace()

-> REPLACE() takes two arguments - 1. the old string that needs to be replaced

2. new string that replaces the old string

old_string.replace(" "."")

for the above problem:

string ='MARIE ASSEMBLY'

print(string[::-1].replace(" ",""))

OUTPUT:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote