Please help me work these out in assembly language Mips plea

Please help me work these out in assembly language Mips please include the c code as well

Web Sources for summaries of the assembly language Examples of high-level code with equivalent assembly translations for: for loop while loop if/else if/else integer array initialization dynamic memory allocation (syscall 9 in MIPS, malloc in C) string initialization dynamic memory allocation (syscall 9 in MIPS, malloc in C) A recursive function call A program in high-level and equivalent assembly that finds the length of a string OR a program of your choice in both high-level and equivalent assembly as approved by the assessor.

Solution

Example for FOR loop in C code:

#include<stdio.h>

int main()

{

int a;

/* for loop execution*/

for(a=0;a<9;a=a+1)

{

printf(\"value of a: %d\ \",a);

}

return 0;

}

OUTPUT:

value of a:0

value of a:1.............

value of a:9

Assembly code for above example:

DATA SEGMENT

DATA ENDS

CODE SEGMENT

ASSUME DS:DATA,CS:CODE

START:

MOV AX,DATA

MOV DS,AX

MOV BL,00H

MOV CH,00H

MOV CL,0AH

L1 : MOV DH,00H

MOV DL,BL

ADD DL,\'0\'

MOV AH,02H

INT 21H

INC BL

LOOP L1

MOV AH,4CH

INT 21H

CODE ENDS

END START

;

OUTPUT:

0123456789

While loop in C program:

word=\"english\";

var=3;

while(var<=3)

var++;

printf(\"sorry you have exceeded 3 trails\");

Above program in ASM:

mov AL, 0

start:

cmp AL, 3 \'compare

jg exit_trails

add AL, 1 \'increment

jmp start

exit_trails:

//your message here

ret

Example for If-else statement whether the number is even or odd in c:

#include<stdio.h>

int main()

{

int num;

/*read numbers from user*/

printf(\"Enter any number to check even or odd:\");

scanf(\"%d\",&num);

/* check if the number is divisible by 2 */

if(num%2==0)

{

printf(\"Number is evev.\ \");

}

else

{

printf(\"number is odd.\ \");

}

return 0;

}

Above program in ASM:

AUUEME CS:CODE,DS:DATA

DATA SEGMENT

MSG DB 10,13,\'ENTER A NUMBER=$\'

MSG1 DB 10,13,\'NUMBER IS EVEN$\'

MSG2 DB 10,13,\'NUMBER IS ODD$\'

DATA ENDS

CODE SEGMENT

START:

MOV BX,DATA

MOV DS,BX

LEA SI,MSG

CALL PRINT

MOV AH,01H

INT21H

SAR AL,01

JC ODD

LEA S1,MSG1

CALL PRINT

JMP TERMINANT

ODD:

LEA S1,MSG2

CALL PRINT

TERMINANT:

MOV AH,4CH

INT 21H

PRINT PROC

MOV DX,S1

MOV AH,09H

INT 21H

RET

PRINT ENDP

CODE ENDS

END START

/*

OUTPUT------------

C:\\Usr\\student>CD C:\\Tasm 1.4\\tasm

C:\\Tasm 1.4\\Tasm>TASM ODDEVE

turbo assembler version 3.0 Copyright (c)1988, 1991 borland internationa

Assembling file: ODDEVE.ASM

Error message: none

Passes:

Remaining memory: 460k

Enter number:3

Number is even

C:\\TASM1-1.4\\Tasm>oddeve

Enter Number=1

Number is odd

C:\\TASM1-1.4\\Tasm>

*/

Please help me work these out in assembly language Mips please include the c code as well Web Sources for summaries of the assembly language Examples of high-le
Please help me work these out in assembly language Mips please include the c code as well Web Sources for summaries of the assembly language Examples of high-le
Please help me work these out in assembly language Mips please include the c code as well Web Sources for summaries of the assembly language Examples of high-le
Please help me work these out in assembly language Mips please include the c code as well Web Sources for summaries of the assembly language Examples of high-le

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site