Write a new subroutine in assembly to convert the upper-case letters to lower-case letter. Example of lower case to upper is provided below:
Let’s look at a subroutine to capitalize all the lower-case letters in the string. We need to load each character, check to see if it is a letter, and if so, capitalize it.
Each character in the string is represented with its ASCII code. For example, ‘A’ is represented with a 65 (0x41), ‘B’ with 66 (0x42), and so on up to ‘Z’ which uses 90 (0x5a). The lower case letters start at ‘a’ (97, or 0x61) and end with ‘z’ (122, or 0x7a). We can convert a lower case letter to an upper case letter by subtracting 32.
__asm void my_strcpy(const char *src, char *dst){
loop
LDRB r2, [r0] ; Load byte into r2 from mem. pointed to by r0 (src pointer)
ADDS r0, #1 ; Increment src pointer
STRB r2, [r1] ; Store byte in r2 into memory pointed to by (dst pointer)
ADDS r1, #1 ; Increment dst pointer
CMP r2, #0 ; Was the byte 0?
BNE loop ; If not, repeat the loop
BX lr ; Else return from subroutine
}
__asm void my_capitalize(char *str){
cap_loop
LDRB r1, [r0] ; Load byte into r1 from memory pointed to by r0 (str pointer)
CMP r1, #'a'-1 ; compare it with the character before 'a'
BLS cap_skip ; If byte is lower or same, then skip this byte
CMP r1, #'z' ; Compare it with the 'z' character
BHI cap_skip ; If it is higher, then skip this byte
SUBS r1,#32 ; Else subtract out difference to capitalize it
STRB r1, [r0] ; Store the capitalized byte back in memory
cap_skip
ADDS r0, r0, #1 ; Increment str pointer
CMP r1, #0 ; Was the byte 0?
BNE cap_loop ; If not, repeat the loop
BX lr ; Else return from subroutine
}
/*----------------------------------------------------------------------------
MAIN function
*----------------------------------------------------------------------------*/
int main(void){
const char a[] = "Hello world!";
char b[20];
my_strcpy(a, b);
my_capitalize(b);
while (1)
;
}.MODEL SMALL
.DATA
MSG DB 0DH,0AH, ' ENTER THE STRING :-----> : $'
MSG2 DB 0DH,0AH, ' YOUR STRING IS :-----> : $'
STR1 DB 255 DUP(?)
ONE DB ?
TWO DB ?
.CODE
BEGIN:
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG
MOV AH,09H
INT 21H
LEA SI,STR1
MOV AH,01H
READ:
INT 21H
MOV BL,AL
CMP AL,0DH
JE DISPLAY
XOR AL,20H
MOV [SI],AL
INC SI
;CMP BL,0DH
JMP READ
DISPLAY:
MOV AL,'$'
MOV [SI],AL
LEA DX,MSG2
MOV AH,09H
INT 21H
LEA DX,STR1
MOV AH,09H
INT 21H
; MOV AH,4CH
; INT 21H
.EXIT
END BEGIN
Write a new subroutine in assembly to convert the upper-case letters to lower-case letter. Example of...
Write a program to read a letter in lower case the convert this letter to upper case and print it. (to convert from lower to upper subtract from the value 20h)
Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...
Please explain
lowing function should allocate space for a new string, copy the nd convert every string from the passed argument into the new string, a lower-case character in the new string into an upper-case modify the original st character (do not ring). Fill-in the blanks and the body of the for0 loop: char* upcase char str)t char p; char* result; result, (char*) malloc( - strcpy( for( p-result; *p!-10': p++) / Fill-in 'A'-65, 'a' 97, 'Z 90, 'z' 122/ return...
6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...
Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...
You’ll create the parser with a 2-part layered approach. You’ll first create a Lexer, which will read characters from a file and output tokens. Then you’ll write the second part, which will process the tokens and determine if there are errors in the program. This program have 3 files Lexer.java, Token.java, Parser.java Part 1 Lexer: The class Lexer should have the following methods: public constructor which takes a file name as a parameter○private getInput which reads the data from the...
This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...
CSC110
Lab 6 (ALL CODING IN JAVA)
Problem: A text file contains a paragraph. You are to read the
contents of the file, store the UNIQUEwords and count the
occurrences of each unique word. When the file is completely read,
write the words and the number of occurrences to a text file. The
output should be the words in ALPHABETICAL order along with the
number of times they occur and the number of syllables. Then write
the following statistics to...