Как зациклить на ассемблере - PullRequest
1 голос
/ 28 ноября 2011

Как бы я вычислил первые 12 значений в последовательности чисел Фибоначчи и смог бы поместить их в EAX reg.и отображать вызов DumpRegs?Используя косвенную адресацию, я знаю, что здесь нужен цикл for, но я не уверен, как это сделать.Любая помощь или советы приветствуются.

      INCLUDE Irvine32.inc

; (insert symbol definitions here)

.data

; (insert variables here)
   Fibonacci BYTE 1, 1, 10 DUP (?)

.code
main PROC

; (insert executable instructions here)


    ; (This below will show hexa contents of string.)
      mov   esi, OFFSET Fibonacci       ; offset the variables
      mov   ebx,1                   ; byte format
      mov   ecx, SIZEOF Fibonacci       ; counter
      call  dumpMem 


    exit        ; exit to operating system
main ENDP

; (insert additional procedures here)

END main

Ответы [ 3 ]

4 голосов
/ 28 ноября 2011

Вы можете сделать цикл следующим образом:

mov ecx,12
your_label:
; your code
loop your_label

Инструкция цикла уменьшает ecx и переходит к указанной метке, если ecx не равно нулю.Вы также можете создать такой же цикл, как этот:

mov ecx,12
your_label:
; your code
dec ecx
jnz your_label
1 голос
/ 28 ноября 2011

Вы определили, что вам нужен цикл for для достижения вашей цели, поэтому, возможно, реализация цикла for в сборке на C поможет вам:

Code Generation for For Loop

for (i=0; i < 100; i++)
{
  . . .
}

      * Data Register D2 is used to implement i.
      * Set D2 to zero (i=0)
      CLR.L D2

  L1  
      . . .
      * Increment i for (i++)
      ADDQ.L #1, D2
      * Check for the for loop exit condition ( i < 100)
      CMPI.L #100, D2
      * Branch to the beginning of for loop if less than flag is set
      BLT.S L1

SOURCE: eventhelix.com

0 голосов
/ 09 сентября 2015
.model small
.stack 100h
.data
   msg db 'Enter height of the square form 1-9: $'
   hash db '#$'
   height db 1
   length db 0
   ctr dw 0
   msgagain db 13,10,'Do you want to repeat the program? $'
   msgend db 13,10,'Program Terminated! Press any key to exit..$'
.code
   mov ax, @data
   mov ds, ax
REPEAT:   
   mov ax, 03
   int 10h

   mov ah, 09
   lea dx, msg
   int 21h

   mov ah, 01
   int 21h

   cmp al, '1'
   jl REPEAT
   cmp al, '9'
   jg REPEAT

   sub al, 48
   mov length, al
   mov bl, 1
   mul bl

   mov height, 1  
   mov di, 1 
   mov ctr, ax

   mov cx, ax
   nextline:
      dec length

      mov ah, 02
      mov bh, 00
      mov dl, length
      mov dh, height
      int 10h

      mov cx, di
      hashtags:
         mov ah, 09
         lea dx, hash
         int 21h
      loop hashtags      

      inc di
      inc height
      mov cx, ctr
      dec ctr
   loop nextline

   mov ah, 09
   lea dx, msgagain
   int 21h

   mov ah, 01
   int 21h

   cmp al, 'Y'
   je REPEAT
   cmp al, 'y'
   je REPEAT   

   mov ah, 09
   lea dx, msgend
   int 21h

   mov ah, 01
   int 21h

   mov ah, 4ch
   int 21h

END
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...