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

ARM assembly language to convert integer, 1194684 to hexadecimal. The signature

ID: 3685804 • Letter: A

Question

ARM assembly language to convert integer, 1194684 to hexadecimal.

The signature of the routine is char*int2hex(int convert) where:

int convert = 1194684;

The output must be in the format 0Xdddddddd

I need the ARM Assembly Language NOT the C-code.

The C program is:

#include <stdlib.h>
#include <stdio.h>

extern char * int2hex( int convert ) ;

int main( int argc, char * argv[] )
{
   int convert = 1194684 ;
   char * result ;
  
   result = int2hex( convert ) ;
   printf( "Integer to hex string: %s ", result ) ;
}

Explanation / Answer

This program will convert a decimal integer to hexadecimal: prnstr macro messageone mov ah, 09h lea dx, messageone int 21h endm data segment buffer1 db "Please Enter an integer number : $" buffer2 db 0ah, "Invalid integer..$" buffer3 db 0ah, " TheEquivalent hexadecimal number is : $" buffer4 db 6 db 0 db 6 dup(0) multiplier db 0ah data ends code segment assume cs:code, ds:data start : mov ax, data mov ds, ax mov es, ax prnstr buffer1 mov ah, 0ah lea dx, buffer4 int 21h mov si, offset buf4 + 2 mov cl, byte ptr [si-1] mov ch, 00h subtracthere : mov al, byte ptr [si] cmp al, 30h jnb continue1 prnstr buffer2 jmp stop continue1 : cmp al, 3ah jb continue2 prnstr buffer2 jmp stop continue2 : sub al, 30h mov byte ptr [si], al inc si loop subtracthere mov si, offset buffer4 + 2 mov cl, byte ptr [si-1] mov ch, 00h mov ax, 0000h calculate : mul multiplier mov bl, byte ptr [si] mov bh, 00h add ax, bx inc si loop calculate mov si, offset buffer4 + 2 mov bx, ax mov dx, 0000h mov ax, 1000h convert : mov cx, 0000h convertnow : cmp bx, ax jb continue3 sub bx, ax inc cx jmp convertnow continue3 : cmp cx, 0ah jb continue4 add cl, 37h jmp continue5 continue4 : add cl, 30h continue5 : mov byte ptr [si], cl inc si mov cx, 0010h div cx cmp ax, 0000h jnz convert mov byte ptr [si], '$' prnstr buffer3 prnstr buffer4+2 stop : mov ax, 4c00h int 21h code ends end start