Assembly Loop Cycle, from 0 to 9?

2

Good, I have to do a cycle in assembly language from 1 to 10 that shows the numbers, I already have the cycle but I do not know how to make the interruption to show the numbers on the screen, the cycle is as follows:

Assembly

.model small
.stack
.data
.code
    PAGE 60,132
    TITLE EJLOOP (EXE) ilustración de LOOP
    ; ----------------------------------------…
    ORG 100H
    BEGIN PROC NEAR
        MOV AX,01 ; iniciación de AX
        MOV BX,01 ; BX y
        MOV DX,01 ; DX a 01
        MOV CX,10 ; iniciar
        A20: ; número de iteraciones
        LOOP A20 ; decrementar CX
        ; iterar si es diferente de 0
        MOV AX, 4C00H ; salida a DOS
        INT 21H
    BEGIN ENDP ; fin de procedimiento
.exit
end

But how do I interrupt to show the numbers ???? Thanks!

    
asked by Guillermo Navarro 01.10.2016 в 00:52
source

1 answer

2

In assembler there are many ways to do loops as you want, the most basic could be a jump combined with the use of tags .

For example:

MOV CL, 10
ETIQUETA1:
<LO-QUE-QUIERAS-HACER-DENTRO-DEL-LOOP>
DEC CL
JNZ ETIQUETA1

( JNZ means Jump if not zero )

But you can also use the loop statement, something like:

LOOP ETIQUETA1

And ETIQUETA1 will contain the code you want to execute inside the loop. Here there is no counter because the statement loop assumes that this counter is the register ECX , so that a more complete example could be like this:

mov ECX,10
ETIQUETA1:
<LO-QUE-QUIERAS-HACER-DENTRO-DEL-LOOP>
loop ETIQUETA1

A functional example that prints the numbers from 1 to 9 would go like this:

section .text
   global _start        ;must be declared for using gcc

_start:                 ;tell linker entry point
   mov ecx,10
   mov eax, '1'

l1:
   mov [num], eax
   mov eax, 4
   mov ebx, 1
   push ecx

   mov ecx, num        
   mov edx, 1        
   int 0x80

   mov eax, [num]
   sub eax, '0'
   inc eax
   add eax, '0'
   pop ecx
   loop l1

   mov eax,1             ;system call number (sys_exit)
   int 0x80              ;call kernel
section .bss
num resb 1

You can find more about mov and interrupts (or instructions).

I hope it serves you.

    
answered by 01.10.2016 в 07:58