Question

In this problem, you will write a LC-3 assembly code that removes blank spaces from a...

In this problem, you will write a LC-3 assembly code that removes blank spaces from a string. Assume that the string starts at memory location 0x5000, and is terminated by a ‘\0’ character (ASCII value = 0). Your program should store the modified string in the memory location starting at 0x5100. You do not need to modify the original string stored at 0x5000. You can assume that the original string at 0x5000 will always be less than 100 characters in length, and it will always start with a letter (A-Z, lowercase or uppercase possible). Note: If the modified string has 7 characters, and the original string has 15 characters, the last 8 characters of your modified string should be all ‘%’ (ASCII value = 0x25). For example: If the original string at 0x5000 was “aa 12 d e f”, the modified string at 0x5100 after your program completes execution should be “aa12def%%%%”. Note that the original string has 4 blank space characters, and the modified string has 4 extra “%” in the end. Your code should start at memory location 0x3000.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

; remblank.asm ORIG x3000 LEA RO, input LD R1, INPUT STRING L1 LDR R2, R0 , #0 ADD R3 , R2, #0 BRz done : start at memory loc

Sample output:

compile remblank.asm

LC3 Simulator File About Controls Next Step Continue Stop Suspended as remblank.asm Loaded object file DLC3lc3os.obj Loaded s

load remblank.obj

run

LC3 Simulator File About Controls Continue Hated as remblank.asm Assembly of remblank.asm completed without errors or warnin

Code to copy:

;remblank.asm
.ORIG x3000           ; start at memory location 0x3000
LEA R0,input           ; Load starting address of input string
LD R1, INPUT_STRING       ; R1=x5000
L1               ; loop to store input string at location x5000
LDR R2,R0,#0           ; read current character into R2
ADD R3,R2,#0           ; R3=R2+0
BRz done           ; if current character is zero(null character)
               ; go to label done
STR R2,R1,#0           ; otherwise, store current charcter into current location
ADD R0,R0,#1           ; go to next character
ADD R1,R1,#1           ; go to next location
BR L1               ; go to L1
done STR R2,R1,#0       ; write also null character
LD R0,INPUT_STRING        ; Load input string location
PUTS               ; print input string
LD R0,NEW_LINE           ; print new line
OUT

LD R0, INPUT_STRING       ; to track the location at the input string
LD R1, OUTPUT_STRING       ; to track the location at the output string
LD R6, BLANK_SPACE       ; R6 = 32, ASCII value of blank space ' '
NOT R6, R6           ; R6 = -32
ADD R6, R6, #1  
AND R3,R3,#0           ; R3=0(to keep track number of blank spaces)   
LOOP LDR R2, R0, #0       ; R2 contains the character at location R0+0
BRnz INPUT_OVER           ; If current character is null goto INPUT_OVER
ADD R0,R0, #1           ; Increment R0 to access next character in input string  
ADD R5,R2,R6           ; R5=R2-32
BRz SKIP_STORING_SPACE       ; Check and skip storing if character is blank space
STR R2,R1,#0           ; Store current character (in R2) to output string
ADD R1,R1,#1           ; Increment R1 to store next character
BRnzp LOOP           ;jump to loop
SKIP_STORING_SPACE ADD R3,R3,#1
BRnzp LOOP           ;jump to loop
INPUT_OVER LD R2,REPLACE    ;R2 = x25
; store %s
LOOP1 ADD R3,R3,#-1       ;Decrement R3
   BRz END
   STR R2,R1,#0       ;Store % to current location in output string
   ADD R1,R1,#1       ;Increment R1 to go to next location
   BRnzp LOOP1
END STR R2,R1,#0       ;Store 0 at the end of string
  
LD R0,OUTPUT_STRING
PUTS               ; print the modified string
   HALT
input .STRINGZ "aa 12 d e f" ; aa 12 d e f
INPUT_STRING .FILL x5000
OUTPUT_STRING .FILL x5100
BLANK_SPACE .FILL x20
REPLACE .FILL x25
NEW_LINE .FILL xA

Add a comment
Know the answer?
Add Answer to:
In this problem, you will write a LC-3 assembly code that removes blank spaces from a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this problem, you will write an assembly program (LC-3 assembly language) to process a string...

    In this problem, you will write an assembly program (LC-3 assembly language) to process a string starting at memory location x5000, and is terminated by a ‘\0’ character (ASCII value = 0). For a given string beginning at memory location x5000, convert all the upper-case English letters (A-Z) to lower-case, and all the lower case (a-z) to upper case. For example, if the string is “iLOVEComputerScience252”, the string after the processing should be: “IlovecOMPUTERsCIENCE252”. Store the string after the processing...

  • In this problem, you will write an assembly program (LC-3 assembly language) to process a string ...

    In this problem, you will write an assembly program (LC-3 assembly language) to process a string starting at memory location x5000, and is terminated by a ‘\0’ character (ASCII value = 0). For a given string beginning atmemory location x5000, convert all the upper-case English letters (A-Z) to lower-case, and all the lower case (a-z) to upper case. For example, if the string is “iLOVEComputerScience252”, the string after the processing should be: “IlovecOMPUTERsCIENCE252”. Store the string after the processing to...

  • Write an LC-3 program (starting at memory location 0x3000) to take a string as input and...

    Write an LC-3 program (starting at memory location 0x3000) to take a string as input and then output information about this string. The end of the string will be denoted with the "#" character. Once the "#" has been found, output the following in order: 1) The letter “u” followed by the number of uppercase letters in the string (A-Z) 2) The letter “l” followed by the number of lowercase letters in the string (a-z) 3) The letter “n” followed...

  • MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and...

    MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and print a simple checksum for each string. Make your string long enough to hold 50 characters. Don't forget to leave space for the null byte. Our checksum algorithm will produce a value which you can print with the syscall for printing a character. Stop reading strings when the user enters ".". The syscall to read a string (sycall code 8) adds a newline to...

  • 10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string...

    10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string for all occurrences of string2. When it finds an occurrence of Programming Challenges string2, it should replace it with string. For example, suppose the three arguments have the following values: stringt: "the dog jumped over the fence" string 2 "the" string3: "that" With these three arguments, the function would return a...

  • Create a program that performs the following operations: 1. Prompt for and accept a string of...

    Create a program that performs the following operations: 1. Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 #create space for string input The syscall to place input into the buffer looks like: li $v0,8 # code for syscall read_string la $a0, buffer #tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer is syscall 2....

  • Assembly Programming Question. Read keystroke, reverse case and display, stop on ESC. Also relevant: Also relevant:...

    Assembly Programming Question. Read keystroke, reverse case and display, stop on ESC. Also relevant: Also relevant: Also relevant (though you cant use Irvine16.inc): Assembly Programming Question. Read keystroke, reverse case and display, stop on ESC. Assembly Programming Question. Read keystroke, reverse case and display, stop on ESO. 3. Write a program that reads a user keystroke and if it?s an alphabetical character, reverses it case then displays it. The program should stop when the user hits the ESC key (1Bh)....

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Prompt the user and read in a string. Make your string large enough to hold 100...

    Prompt the user and read in a string. Make your string large enough to hold 100 characters. 2. Count the number of words in the string. A word is one or more non-blank characters separated by one or more blanks. My suggestion is to use a flag (a boolean variable) to indicate whether or not you are in a word. Then you know you have found a word when the flag indicates that you are in a word and the...

  • Write a Python program (remove_first_char.py) that removes the first character from each item in a list...

    Write a Python program (remove_first_char.py) that removes the first character from each item in a list of words. Sometimes, we come across an issue in which we require to delete the first character from each string, that we might have added by mistake and we need to extend this to the whole list. Having shorthands (like this program) to perform this particular job is always a plus. Your program should contain two functions: (1) remove_first(list): This function takes in a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT