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

use MIPS program 1. This program will read a character string and counts the num

ID: 3607045 • Letter: U

Question

use MIPS program

1. This program will read a character string and counts the number of characters and prints the output and print it out. character you are looking for and print. 2. Given an array element find out minimum and maximum value 3. You are given a character string, count the occurrence of a specific 4. You are given a character string, reverse the string and print. 5. Write a program that takes Fahrenheit value and prints it in the Celsius. 6. Write a program that generates and adds up all even numbers from 1 to 100.

Explanation / Answer

1 //——-Read the characterer string and count the number of characters.—//

DATA SEGMENT

STR1 DB "ENTER YOUR STRING HERE ->$"

STR2 DB "YOUR STRING IS ->$"

STR3 DB "STRING LENGTH->$"

INSTR1 DB 20 DUP("$")

NEWLINE DB 10,13,"$"

LN DB 5 DUP("$")

N DB "$"

S DB ?

DATA ENDS

// ===Code segment ==//

CODE SEGMENT

ASSUME DS:DATA,CS:CODE

/// == Start code ==/

START:

MOV AX,DATA

MOV DS,AX

LEA SI,INSTR1

//= get the string =/

;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 string string and count //

;PRINT THE STRING

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

;PRINT LENGTH OF STRING (DIRECT)

MOV AH,09H

LEA DX,STR3

INT 21H

MOV BL,INSTR1+1

ADD BL,30H

MOV AH,02H

MOV DL,BL

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

CODE ENDS

END START

Second Program

// == Find the Maximum and Minimum in given array ==/

DATA SEGMENT

ARR DB 1,2,3,4,5,6,7,8

LEN DW $-ARR

MIN DB ?

MAX DB ?

DATA ENDS

// == code segment==/

CODE SEGMENT

ASSUME DS:DATA CS:CODE

START:

MOV AX,DATA

MOV DS,AX

// check array //

LEA SI,ARR

MOV AL,ARR[SI]

MOV MIN,AL

MOV MAX,AL

// find maximum //

MOV CX,LEN

REPEAT:

MOV AL,ARR[SI]

CMP MIN,AL

JL CHECKMAX

// find minimum//

MOV MIN,AL

CHECKMAX:

CMP MAX,AL

JG DONE

// print //

MOV MAX,AL

DONE:

INC SI

LOOP REPEAT

MOV AH,4CH

INT 21H

CODE ENDS

END START

// ==== Reverse of String ==== //

DATA SEGMENT

STR1 DB "ENTER YOUR STRING HERE ->$"

STR2 DB "STRING IS ->$"

STR3 DB "REVERSE STRING ->$"

INSTR1 DB 20 DUP("$")

RSTR DB 20 DUP("$")

NEWLINE DB 10,13,"$"

N DB ?

S DB ?

DATA ENDS

// code segment //

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 string

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

// print reverse //

MOV AH,09H

LEA DX,STR3

INT 21H

MOV CL,INSTR1+1

ADD CL,1

ADD SI,2

   L1:

INC SI

CMP BYTE PTR[SI],"$"

JNE L1

DEC SI

LEA DI,RSTR

   L2:MOV AL,BYTE PTR[SI]

MOV BYTE PTR[DI],AL

DEC SI

INC DI

LOOP L2

MOV AH,09H

LEA DX,NEWLINE

INT 21H

MOV AH,09H

LEA DX,RSTR

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

MOV AH,4CH

INT 21H

CODE ENDS

END START

4)

// occurence of specific character //

DATA SEGMENT

STR1 DB "ENTER STRING ->$"

STR2 DB "OCCURENCE OF A : ->$"

STR11 DB " STRING IS : ->$"

OCC DB "A"

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 the 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 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

“check A in string “

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],"C"

JNE L2

ADD BL,1

JMP L2

// Print //

L1: MOV AH,09H

LEA DX,NEWLINE

INT 21H

ADD BL,30H

MOV AH,02H

MOV DL,BL

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

MOV AH,4CH

INT 21H

CODE ENDS

END START