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

I am a beginner trying to learn programing. So, I want you to use simple steps l

ID: 3889099 • Letter: I

Question

I am a beginner trying to learn programing. So, I want you to use simple steps like LDR, STR, ADD etc......

1. A string is stored in the memory at location string. Write an ARM assembly language program in ARMSimulator to count the number of characters in the given string. The string is terminated with a 0. You can use the following assembler directive to store the string:

Use R0 to store the result.

2. Modify the program written in Problem 1 to count the number of times a particular character appears in the string. The character is stored in the memory after the “string” as follows:

Use R1 to store the result.

Explanation / Answer

Problem 1 :

DATA SEGMENT

STR1 DB "ENTER YOUR STRING HERE ->$"

STR2 DB "YOUR STRING IS ->$"

STR3 DB "LENGTH OF STRING IS(DIRECT) ->$"

STR4 DB "LENGTH OF STRING IS(COUNT) ->$"

INSTR1 DB 20 DUP("$")

NEWLINE DB 10,13,"$"

LN DB 5 DUP("$")

N DB "$"

S DB ?

DATA ENDS

CODE SEGMENT

ASSUME DS:DATA,CS:CODE

START:

MOV AX,DATA

MOV DS,AX

LEA SI,INSTR1

;GET STRING

MOV AH,09H

LEA DX,STR1

INT 21H

MOV AH,0AH

MOV DX,SI

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

MOV AH,09H

LEA DX,STR2

INT 21H

MOV AH,09H

LEA DX,INSTR1+2

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

MOV AH,09H

LEA DX,STR3

INT 21H

MOV BL,INSTR1+1

ADD BL,30H

MOV AH,02H

MOV DL,BL

MOV R0,DL

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

CODE ENDS

END START

Problem 2 :

DATA SEGMENT

STR1 DB "ENTER FIRST STRING HERE ->$"

STR2 DB "OCCURENCE OF C IS : ->$"

STR11 DB "GIVEN STRING IS : ->$"

OCC DB "C"

N DB ?

INSTR1 DB 20 DUP("$")

NEWLINE DB 10,13,"$"

DATA ENDS

CODE SEGMENT

ASSUME DS:DATA,CS:CODE

START:

MOV AX,DATA

MOV DS,AX

LEA SI,INSTR1

;GET STRING

MOV AH,09H

LEA DX,STR1

INT 21H

MOV AH,0AH

MOV DX,SI

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

;PRINT THE STRING

MOV AH,09H

LEA DX,STR11

INT 21H

MOV AH,09H

LEA DX,INSTR1+2

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

;FIND THE OCCURENCE OF C

MOV AX,00

MOV AH,09H

LEA DX,STR2

INT 21H

MOV BX,00

ADD SI,1

  

L2:INC SI

CMP BYTE PTR[SI],"$"

JE L1

CMP BYTE PTR[SI],"T"

JNE L2

ADD BL,1

JMP L2

L1: MOV AH,09H

LEA DX,NEWLINE

INT 21H

ADD BL,30H

MOV AH,02H

MOV DL,BL

MOV R1,DL

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

MOV AH,4CH

INT 21H

CODE ENDS

END START