Question

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 to memory location defined by x5100. Your program should start at memory location x3000.

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

Program:

Sample output:

load lc3os.obj

then compile q.asm (as q.asm)

load q.obj

Run by clicking on continue button

Code to copy:

; q3.asm
.ORIG x3000                  ; start at memory location 0x3000
;---------------------------------------------------------------------------
; for testing storing the string “IlovecOMPUTERsCIENCE252” at location x5000
;---------------------------------------------------------------------------
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
;---------------------------------------------------------------------------
; print input string
;---------------------------------------------------------------------------
LD R0,INPUT_STRING           ; Load input string location
PUTS                           ; print input string
LD R0,NEW_LINE              ; print new line
OUT
;---------------------------------------------------------------------------
; process the input string and store the converted string at 0x5100
;---------------------------------------------------------------------------
LD R0, INPUT_STRING          ; R0=starting address of the input string
LD R1, OUTPUT_STRING          ; R1=starting address of the output string

LOOP LDR R2, R0, #0          ; R2 contains the character at location R0+0
BRnz PROCESS_OVER           ; If current character is null goto label PROCESS_OVER
; check whether the letter is upper case or not(for upper case x, 41<=x<=5A)
LD R3,UCS      
NOT R3,R3
ADD R3,R3,#1                ; R3=-41
ADD R3,R2,R3
BRn CHECK_UPPER             ; if x-41<0, go to CHECK_UPPER
LD R3,UCE
AND R4,R4,#0
ADD R4,R4,R2
NOT R4,R4
ADD R4,R4,1                 ; R4=-x
ADD R3,R3,R4
BRn CHECK_UPPER             ; if 5A-x < 0, go to CHECK_UPPER
; if the letter is upper case add gap(32) to it to convert into lower case letter
LD R4,GAP
ADD R4,R4,R2
STR R4,R1,#0                  ; Store current character (in R2) to output string
BRnzp NEXT                    ; go to next iteration
; check whether the letter is lower case or not(for lower case x, 61<=x<=7A)
CHECK_UPPER LD R3,LCS
NOT R3,R3
ADD R3,R3,#1                ; R3=-61
ADD R3,R2,R3
BRn STORE                   ; if x-41<0, go to STORE(to store the character as it is)
LD R3,LCE
AND R4,R4,#0
ADD R4,R4,R2
NOT R4,R4
ADD R4,R4,1                 ; R4=-x
ADD R3,R3,R4
BRn STORE                   ; if 7A-x<0, go to STORE(to store the character as it is)
; if the letter is lower case subtract gap(32) from it to convert into upper case letter
LD R4,GAP
NOT R4,R4
ADD R4,R4,#1
ADD R4,R4,R2
STR R4,R1,#0
BRnzp NEXT                    ; go to next iteration
STORE STR R2,R1,#0         ; Store current character as it is, to output string
NEXT ADD R0,R0, #1          ; Increment R0 to access next character of the input string
ADD R1,R1,#1                  ; Increment R1 to store next character into output string
BRnzp LOOP                  ; jump to loop
PROCESS_OVER STR R2,R1,#0    ; Store null(0) at the end of the output string
;---------------------------------------------------------------------------
; print converted string
;---------------------------------------------------------------------------
LD R0,OUTPUT_STRING
PUTS                           ; print the modified string
   HALT                     ; exit the program
;---------------------------------------------------------------------------
; declare the necessary data
;---------------------------------------------------------------------------
input .STRINGZ "iLOVEComputerScience252"
INPUT_STRING .FILL x5000
OUTPUT_STRING .FILL x5100
NEW_LINE .FILL xA
LCS .FILL x61       ; (97)dec
LCE .FILL x7A       ; (122)dec
UCS .FILL x41       ; (65)dec
UCE .FILL x5A       ; (90)dec
GAP .FILL x20       ; (32)dec

Add a comment
Know the answer?
Add Answer to:
In this problem, you will write an assembly program (LC-3 assembly language) to process a string...
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 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...

  • 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...

  • 2. Searching a String: Write a MIPS assembly language program to do the following: Read a...

    2. Searching a String: Write a MIPS assembly language program to do the following: Read a string and store it in memory. Limit the string length to 100 characters. Then, ask the user to enter a character. Search and count the number of occurrences of the character in the string. The search is not case sensitive. Lowercase and uppercase letters should be equal. Then ask the user to enter a string of two characters. Search and count the number of...

  • 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...

  • Question: WRITE A PROGRAM IN LC-3 ASSEMBLY LANGUAGE. DO NOT ... WRITE A PROGRAM IN LC-3...

    Question: WRITE A PROGRAM IN LC-3 ASSEMBLY LANGUAGE. DO NOT ... WRITE A PROGRAM IN LC-3 ASSEMBLY LANGUAGE. DO NOT USE PYTHON, JAVA, C or C++ or OTHERS. Your task is to write a program that counts the number of 1 bits of the value stored at location given by Datal. Your program should print the count (in hexadecimal, as it is easier) along with an appropriate heading. Test your program with the following values stored in Datal: a xFFFE...

  • Write an Assembly language program to: A- Store the following text " Welcome to Assembly Language" in the ROM a...

    Write an Assembly language program to: A- Store the following text " Welcome to Assembly Language" in the ROM at 200H B- Find how many e letters in this word and store the count in the RAM in location 40H Write an Assembly language program to: A- Store the following text " Welcome to Assembly Language" in the ROM at 200H B- Find how many e letters in this word and store the count in the RAM in location 40H

  • Write a program in LEGv8 assembly to copy a null-terminated ASCII string from array y to array x;...

    Write a program in LEGv8 assembly to copy a null-terminated ASCII string from array y to array x; converting every 'a' character in the source string to 'b' in the destination string. In other words, for each character in array y: else Assume that the base address of the arrays x and y are in registers X0 and X1, respectively. The ASCII code for characters 'a' and 'b' is 113 and 114 respectively [25 pts]. * Null-terminated means that a...

  • 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...

  • Exercise #4: Some Operations on Strings Write a program that uses a C-string to store a...

    Exercise #4: Some Operations on Strings Write a program that uses a C-string to store a string entered from the keyboard (in lower case letters). The program will then provide 6 options about operations performed on the input string in the form of a menu, as shown in the following sample Input/Output. The 6 operations are given below: 1. print the string 2 reverse the string 3. print the length of the string 4. convert the lower letters to upper...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

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