Click here to Skip to main content
15,905,566 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.. i have just started studying assembly.. i have written a code to print the numbers in reverse order.. but i want to know that how should we made increment in the address as i have stored every number in a variable (DB) and i m calling from its address... this is the code

ASM
title Printing numbers in reverse order.
.model small
.stack 100h
.data
    num DB 0,1,2,3,4,5,6,7,8,9
    result DB ?
.code
    main proc
        mov ax,@data
        mov ds,ax
        mov bx,offset result
        mov al,num+9
        add al,30h
        mov [bx],al
        mov al,num+8
        add al,30h
        mov [bx+1],al
        mov al,num+7
        add al,30h
        mov [bx+2],al
        mov al,num+6
        add al,30h
        mov [bx+3],al
        mov al,num+5
        add al,30h
        mov [bx+4],al
        mov al,num+4
        add al,30h
        mov [bx+5],al
        mov al,num+3
        add al,30h
        mov [bx+6],al
        mov al,num+2
        add al,30h
        mov[bx+7],al
        mov al,num+1
        add al,30h
        mov [bx+8],al
        mov al,num
        add al,30h
        mov [bx+9],al
       
        mov cx,10
        mov ah,2
        mov dl,[bx]            //What is the mistake i am incrementing
                                 bx by 1 so y it's not taking the next
                                  address to print

show:   int 21h
        inc bx
        loop show

        mov ah,4ch
        int 21h
    main endp
end main
Posted

You have the label in the wrong place, you need something like:
show:
        mov dl,[bx]            //What is the mistake i am incrementing
                               //  bx by 1 so y it's not taking the next
                               //   address to print
        int 21h
        inc bx
        loop show

You could also store your numbers as characters in the first place by
num DB '0','1','2' ...
 
Share this answer
 
v2
Comments
Moiz90 12-Oct-10 18:28pm    
Okay thanks.... But i have stored every value in var result in reverse order, and now i want to show every value of var result. what should i do for this.. ??

as the address of var result is save in bx so i am incrementing bx so that it shows me the next value every time .. is there any other method to do the same thing..??

if it is like this that the var result address is let suppose 0001 then the values are saved like this
0001----------9
0002----------8
0003----------7
0004----------6
0005----------5
0006----------4
0007----------3
0008----------2
0009----------1
0010----------0

when i m incrementing bx by 1 then y it is not coming at 0002 and print 8.. ???
what is the mistake here..??
Okay thanks.... But i have stored every value in var result in reverse order, and now i want to show every value of var result. what should i do for this.. ??

as the address of var result is save in bx so i am incrementing bx so that it shows me the next value every time .. is there any other method to do the same thing..??

if it is like this that the var result address is let suppose 0001 then the values are saved like this
0001----------9
0002----------8
0003----------7
0004----------6
0005----------5
0006----------4
0007----------3
0008----------2
0009----------1
0010----------0

when i m incrementing bx by 1 then y it is not coming at 0002 and print 8.. ???
what is the mistake here..??
 
Share this answer
 
Comments
Richard MacCutchan 13-Oct-10 8:19am    
I am not sure what you are doing wrong here. If you moved the label as I suggested then it should work. Try reducing the number of values to just 2 or 3 and then run your program in the debugger and step through it to see what is happening.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900