Hello, I need help for my task.. This is the matrix

1 2 3
4 5 6
7 8 9

the result is 1,4,7,8,9,6,3,2,5

I have to solve this task in assembler 8086 in emu... I need help, it is very important for me. Please help me

I see the code, but I don't understand the task. I try it in emu 8086, but does not print the result which I put in my example.

Could you help,comment your code,?

You should replace strings mov al,[edi];Output [edi] with the code that will print [edi] contents. And replace

Matrix db 0,1,2,3,4,5,6,7,8,9,0Ah,0Bh,0Ch,0Dh,0Eh,0Fh
QDM db 4;Matrix dimension

with your matrix and its dimension.
I do not have emu 8086 on my machine, that is why I did not place printing. It is depending on OS and compiler etc..

Matrix  db 0,1,2,3,4,5,6,7,8,9
     QDM     db 0;Matrix dimension
ends

stack segment
    dw   128  dup(0)
ends

code segment
start:
; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax

        mov     cx,0
        mov     cl,[QDM]
        mov     bx,cx
        mov     di,offset Matrix
mSpiral:
        push    di
 
        mov     al,[di];Output [edi]  
        mov ah, 02h
        int 21h
        push    cx
 
        mov     dx,cx
        mov     cx,dx
        dec     cx
        cmp     cx,0
        jle     mSkD1
mD1:
        add     di,bx
        mov     al,[di];Output [edi] 
        mov ah, 02h
        int 21h
        loop    mD1
mSkD1:
 
        mov     cx,dx
        dec     cx
        cmp     cx,0
        jle     mSkD2
mD2:
        inc     di
        mov     al,[di];Output [edi] 
        mov ah, 2h
        int 21h
        loop    mD2
mSkD2:
 
        mov     cx,dx
        dec     cx
        cmp     cx,0
        jle     mSkD3
mD3:
        sub     di,bx
        mov     al,[di];Output [edi] 
        mov ah, 02h
        int 21h
        loop    mD3
mSkD3:
 
        mov     cx,dx
        sub     cx,2
        cmp     cx,0
        jle     mSkD4
mD4:
        dec     di
        mov     al,[di];Output [edi]  
        mov ah, 02h
        int 21h
        loop    mD4
mSkD4:
 
        pop     cx
 
        pop     di
        add     di,cx
        inc     di
 
        sub     cx,2
        cmp     cx,0
        jle     mEx
        jmp     mSpiral
mEx:

I tried this code in EMU 8086, I change the parts you said to me about print. Is this all right?? It doesn't print result 1,4,7,8,9,6,3,2,5 in my example. What is wrong?? tnx

Think of your matrix like this:
it does not look like this in memrory

1 2 3
 4 5 6
 7 8 9

it looks like: 1 2 3 4 5 6 7 8 9 (spaces added for clarity)

So, load the array, print the first number then add 3 to the address print number, add 3 to the address and print number, print next 2 numbers, subtract 3 and print number, subtract 3 again and print number, sub 1 print number, sub 1 and print final number...

Your explanation was very useful for me. You help me to solve my problem. the input is 1,2,3,4,5,6,7,8,9 and the output is 1, 4, 7, 8, 9, 6, 3, 2, 5, 1. It wasn't difficult after your explanation.

I see you are good programmer, so I have just one more question for, if you can help me.
My task was to print the result. If the question was to make another matrix2 and load in the memory not to print. How can this realise it???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.