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

Write a program in ARM assembly language (which can be executed on ARMSim simula

ID: 3605305 • Letter: W

Question

Write a program in ARM assembly language (which can be executed on ARMSim simulator) to convert an ASCII string containing positive or negative integer decimal string to an integer. Input is given as null-terminated string stored at location given by the label value. The string can containing an optional '+' or '' followed by some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register R1. If a non-digit character appears anywhere in the string, your program should stop with the value 1 in register R1. For example, if input is "24" (or in ASCII 0x32, 0x34, 0x00) then register R1 should contain the value 24ten. (Hint: The ARM MUL instruction takes two registers as input. There is no "MULI" instruction. Thus, just store the constant 10 in a register.)

Explanation / Answer

DATA SEGMENT

     NUM DB 0FFH

     RES DB 10 DUP ('$')

DATA ENDS

CODE SEGMENT

        ASSUME DS:DATA,CS:CODE

START:      

    MOV AX,DATA

    MOV DS,AX

  

    MOV AH,0

    MOV AL,NUM

     

    LEA SI,RES

    CALL HEX2DEC

  

    LEA DX,RES

    MOV AH,9

    INT 21H

           

    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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote