Question & Answer: please write the Y86 assembley for the following c code…..

please write the Y86 assembley for the following c code

/*
 * C program to reverse a given integer number and check
 * whether it is a palindrome. Display the given number
 * with appropriate message
 */
#include <stdio.h>
 
void main()
{
    int num, temp, remainder, reverse = 0;
 
    printf("Enter an integer n");
    scanf("%d", &num);
    /*  original number is stored at temp */
    temp = num;
    while (num > 0)
    {
        remainder = num % 10;
        reverse = reverse * 10 + remainder;
        num /= 10;
    }
    printf("Given number is = %dn", temp);
    printf("Its reverse is  = %dn", reverse);
    if (temp == reverse)
        printf("Number is a palindrome n");
    else
        printf("Number is not a palindrome n");
}

Expert Answer

 

DATA SEGMENT
NUM1 DW 12321
NUM2 DW ?
ARRY DB 10 DUP (0)
TEMP DW ?
MSG1 DB 10,13,’STORED NUMBER IN MEMORY IS : $’
MSG2 DB 10,13,’REVERSE NUMBER IS : $’
MSG3 DB 10,13,’NUMBER IS A PALINDROME $’
MSG4 DB 10,13,’NUMBER IS NOT A PALINDROME $’
RES DB 10 DUP (‘$’)
DATA ENDS

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: please write the Y86 assembley for the following c code…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

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

DISPLAY MSG1

MOV AX,NUM1

LEA SI,RES
CALL HEX2DEC

LEA DX,RES
MOV AH,9
INT 21H

LEA SI,ARRY
MOV AX,NUM1

REVE:
MOV DX,0
MOV BX,10
DIV BX
MOV ARRY[SI],DL
MOV TEMP,AX
MOV AX,DX

INC SI
MOV AX,TEMP
CMP TEMP,0
JG REVE

LEA DI,ARRY
LAST:
INC DI
CMP ARRY[DI],0
JG LAST

DEC DI
MOV AL,ARRY[DI]
MOV AH,0
MOV NUM2,AX
MOV CX,10
CONV:
DEC DI
MOV AL,ARRY[DI]
MOV AH,0
MUL CX
ADD NUM2,AX

MOV AX,CX
MOV BX,10
MUL BX
MOV CX,AX

CMP ARRY[DI],0
JG CONV

DISPLAY MSG2

MOV AX,NUM2

LEA SI,RES
CALL HEX2DEC

LEA DX,RES
MOV AH,9
INT 21H

MOV AX,NUM1
CMP NUM2,AX
JE PALIN

DISPLAY MSG4
JMP FINISH
PALIN:
DISPLAY MSG3

FINISH: MOV AH,4CH
INT 21H
CODE ENDS

HEX2DEC PROC NEAR
MOV CX,0
MOV BX,10

LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1

ADD AL,30H
MOV [SI],AL

LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2DEC ENDP

END START

Still stressed from student homework?
Get quality assistance from academic writers!