Please be sure to answer in SRC assembly language for the SRC compiler. For exam
ID: 3914703 • Letter: P
Question
Please be sure to answer in SRC assembly language for the SRC compiler. For example SRC does not use push/pop and instead would be written (in this example r30=link reg and r31=stack ptr): st r30, (r31) addi r31, r31, 0If this is familiar to you, then you’re probably on the right track. This is for studying for a test I have this evening, so please help if you have an answer, thanks! Problem 1. Code Development (50 points) Write an SRC subroutine that determines whether one string is longer than the other. It should accept as its arguments pointers to the two strings. It should return a negative value if the first string is shorter than the second, a positive value if the first string is longer than the second, and zero if the two strings are equal length. Your subroutine should adhere to the coding convention as used in class. a. Develop a STEP-BY-STEP algorithm for the subroutine in the right side of the table below. b. Write the SRC instructions that implement your algorithm in the left side of the table below. Note that you may want to (but you don't have to) make use of the string length subroutine developed in class. If you choose to use it, you may just call it from your code, assuming that it accepts its argument in Register rO, and returns its result in Register r4. Code Algorithm
Explanation / Answer
CODE:
DATA SEGMENT
STR1 DB 'WELCOME TO'
STR2 DB 'CHEGG'
MSG1 DB 10,13,'Length of the string1:-$'
MSG2 DB 10,13,'Length of the string2:-$'
MSG3 DB 10,13,'Strings are equal length $'
MSG4 DB 10,13,'First string is longer than the second string $'
MSG5 DB 10,13,'First string is shoter than the second string $'
LEN1 DB 0H
LEN2 DB 0H
R4 DB 0H
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA SI,STR1
NEXT1:
CMP [SI],'$'
JE DONE1
INC LEN1
INC SI
JMP NEXT1
DONE1:
DISPLAY MSG1
MOV AL,LEN1
ADD AL,30H
MOV DL,AL
MOV AH,2
INT 21H
LEA DI,STR2
NEXT2:
CMP [DI],'$'
JE DONE2
INC LEN2
INC DI
JMP NEXT2
DONE2:
DISPLAY MSG2
MOV AL,LEN2
ADD AL,30H
MOV DL,AL
MOV AH,2
INT 21H
MOV AL,LEN1
CMP AL,LEN2
MOV R4,AL
CMP R4,0
JE EQUAL
CMP R4,'-$'
JE NEGATIVE
DIPLAY MSG4
JMP EXIT
EQUAL:
DISPLAY MSG3
NEGATIVE:
DISPLAY MSG5
EXIT:
MOV AH,4CH
INT 21H
CODE ENDS
END START
ALGORITHM:
STEP1: Define data segment give the two input strings to the variables,delare the variables and end the data segment.
STEP2: Define macro and end the macro section.
STEP3:Strat the code segment in that we can write the code.
STEP4:Move data to the register and length of the string is stored in a pointers.
STEP5:And length of the strings is stored in a register and compare those register.
STEP6:Comparision value stored in to R4 register.
STEP7:If comparision value is equal to zero then go to the 'EQUAL' label and execute the instructions in that label.
STEP8:If comparision value equal to negative then control go to negative label and execute the instructions in the label.
STEP9:If comparsion value is positive than execute the instruction and display coressponding output
STEP10:cursor go to the exit block and execute corressponding instructions exit block.
STEP11:Code block end and end start.