0

I want to reverse a number in assembly language. I am using MASM and I am getting out of memory error. What I had tried so far:

DATA SEGMENT

    NUM1 DW NUM1 DW 12321
    ARRY DB 10 DUP (0)

    MSG1 DB 10,13,’STORED STRING IN MEMORY IS : $’
    MSG2 DB 10,13,’REVERSE STRING IS : $’
DATA ENDS

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

        DISPLAY NUM1

        LEA SI,NUM2
        LEA DI,NUM1
        ADD DI,5

        MOV CX,6
REVERSE:

        MOV AL,[DI]

        MOV [SI],AL
        INC SI
        DEC DI
        LOOP REVERSE

        DISPLAY MSG2

        DISPLAY STR2

        MOV AH,4CH
        INT 21H
CODE ENDS

END START
5
  • What's your question?
    – Pavlo
    Mar 1, 2016 at 15:33
  • As a courtesy to others please edit your question if you see the formatting is broken. Also, use proper english not "text speak". As to the code, comment your program so we can see what you want the instructions to do. Specify input and output (both actual and expected) including the exact error. Learn to use a debugger so you can step through your code and find mistakes yourself.
    – Jester
    Mar 1, 2016 at 15:35
  • 2
    Where's NUM2 in your code? Where's STR2?
    – JimmyB
    Mar 1, 2016 at 15:37
  • 1
    Btw, your number is stored as a word (dw) but you seem to want to handle it like a string of 6 characters. That doesn't quite match.
    – JimmyB
    Mar 1, 2016 at 15:41
  • what changes should i make in my program
    – Manjesh
    Mar 1, 2016 at 16:29

1 Answer 1

1
NUM1 DW NUM1 DW 12321  ;This produces the error
ARRY DB 10 DUP (0)

Start by changing these definitions into:

NUM1 DB '123456$'  ;$ is needed for displaying it later
NUM2 DB '......$'  ;$ is needed for displaying it later

DISPLAY MSG2
DISPLAY STR2  ; This label does not exist

Next display the result by referring to an existing label:

DISPLAY MSG2
DISPLAY NUM2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.