Copy string in MASM & reverse output using indirect addressing

Viewed 108

The following program should take string input, isolate each character in the string and print the output in reverse order using indirect addressing. The output I get is an identical repeat of the original string. The output should be in reverse.

**** U P D A T E **** Michael & ecm, I took your advice. Now when I check memory location &copyStrg in the debugger I can see the string in reverse order as it should be. However, I can't get it to print. There is something wrong with my print statement in lines 54 & 55.

**** U P D A T E **** Fixed!!!

'''
13      .data
14      msg         BYTE    "Enter a string:", 13, 10, 0
15      strg        BYTE    21 DUP(?)
16      copyStrg    BYTE    SIZEOF strg DUP(?)
17      i           DWORD   ?
18      j           DWORD   ?
19
20      .code
21      main        PROC                        ; Start
22
23          lea     EDX, Msg                    ; Print "Enter a string"
24          call    WriteString
25                      
26          mov     ECX, SIZEOF strg            ; Input strg
27          lea     EDX, strg
28          call    ReadString
29          mov     i, EAX                      ; i = size(strg) 
30          mov     j, 0                        ; j = 0
31          mov     ESI, i                      ; copyStrg[i] = 0
32          mov     copyStrg[ESI], 0
33          
34      
35      lup:                                    ; WHILE i > 0
36          cmp     i, 0                
37          jng     endLup              
38
39          mov     EAX, i                      ;    i--
40          dec     EAX
41          mov     i, EAX
42      
43          mov     ESI, i                      ;    copyStrg[j] = strg[i]
44          mov     EDI, j
45          mov     AL, strg[ESI]
46          mov     copyStrg[EDI], AL
47
48          mov     EBX, j                      ;    j++
49          inc     EBX
50          mov     j, EBX
51          jmp     lup
52   endLup:                                    ; ENDWHILE
53      
54          mov     EDX, OFFSET copyStrg        ; Print copyStrg
55          call    WriteString
56
57          call    CRLF
58          exit                                ; Stop

'''
0 Answers
Related