Multiplication Table Using Nested Loops

X86 MASM build

I created the following code that will print a multiplication table that multiplies 1 * 1, 1 * 2, 1 * 3, ..., 1 * 10. I want to create a continuous table 1 * 1, 1 * 2, 1 * 3, ..., 1 * 10 and another table 2 * 1, 2 * 2, 2 * 3, ..., 2 * 10 and 3 * 1, 3 * 2, 3 * 3, ..., 3 * 10 and etc. Up to 10 * 10, using loops, and recording each procedure separately. However, it is difficult for me to create loops. Please let someone show me. Thank you so much.

INCLUDE Irvine32.inc
.data
  a dword 1
  b dword 1
  z dword ?
  times byte " * ",0
  equals byte " = ",0
.code
main PROC
        call clrscr
        mov ecx,10
        outloop :
         push ecx
         call printtimes

         call crlf
         inc a
         pop ecx
        loop outloop

        call crlf 

        mov ecx,10
        mov a, 1
        outloop1 :
        push ecx 
        call printtimes1 

        call crlf 
        inc a 
        pop ecx 
        loop outloop1 

        call crlf 

        mov ecx,10
        mov a, 1
        outloop2 :
        push ecx 
        call printtimes2 

        call crlf 
        inc a 
        pop ecx 
        loop outloop2 


        exit

main ENDP



    mymul proc
        mov ecx,a
        mov eax,0
        myloop:
         add eax,b
        loop myloop
        mov z,eax

        ret
    mymul endp



    mymul1 proc

        mov ecx,a
        mov eax,0
        mov b, 1
        inc b
        myloop:
         add eax,b
        loop myloop
        mov z,eax

        ret
    mymul1 endp


    mymul2 proc

        mov ecx,a
        mov eax,0
        mov b, 2
        inc b
        myloop:
         add eax,b
        loop myloop
        mov z,eax

        ret
    mymul2 endp




    printtimes proc

      call mymul
        mov eax,a
        call writedec
        mov edx, offset times
        call writestring
        mov eax,b
        call writedec
        mov edx,offset equals
        call writestring
        mov eax,z
        call writedec
        call crlf
        ret 
     printtimes endp

         printtimes1 proc
      call mymul1
        mov eax,a
        call writedec
        mov edx, offset times
        call writestring
        mov eax,b
        call writedec
        mov edx,offset equals
        call writestring
        mov eax,z
        call writedec
        call crlf
        ret 
     printtimes1 endp

     printtimes2 proc
      call mymul2
        mov eax,a
        call writedec
        mov edx, offset times
        call writestring
        mov eax,b
        call writedec
        mov edx,offset equals
        call writestring
        mov eax,z
        call writedec
        call crlf
        ret 
     printtimes2 endp

end main

Results (I want to get this result using nested loops, but it's hard for me to create it):

1*1=1 
2*1=2 
3*1=3 
4*1=4 
5*1=5
6*1=6 
7*1=7 
8*1=8 
9*1=9 
10*1=10 

1*2=2 
2*2=4 
3*2=6 
4*2=8 
5*2=10
6*2=12 
7*2=14 
8*2=16 
9*2=18 
10*2=20 


1*3=3 
2*3=6 
3*3=9 
4*3=12 
5*3=15
6*3=18 
7*3=21 
8*3=24 
9*3=27 
10*3=30 
+4
source share
1 answer
   mov ecx,10
outloop :
    push ecx
    call printtimes
    call crlf
    inc a
    pop ecx
    loop outloop
    call crlf

- 1- (1*1=1 2*1=2 ... 10*1=10)
, ,

  • reset 1
  • b

() , b 10.
ECX , , 10.

    mov     b, 1
OuterLoop:
    mov     a, 1
InnerLoop:
    call    printtimes
    call    crlf
    inc     a
    cmp     a, 10
    jbe     InnerLoop
    call    crlf
    inc     b
    cmp     b, 10
    jbe     OuterLoop

printtimes1, printtimes2, mymul1 mymul2 .

+2

Source: https://habr.com/ru/post/1659310/


All Articles