2011-11-28 3 views
1

피보나치 숫자 시퀀스의 처음 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 

답변

4

당신은 루프를 다음과 같이 할 수 있습니다 :

mov ecx,12 
your_label: 
; your code 
loop your_label 

루프 명령은 ecx을 감소시키고 ecx가 0이 아닌 지정된 레이블로 이동합니다. 또한이 같은 동일한 루프를 구성 할 수 있습니다 : 당신이 당신의 목표, for 루프의 어쩌면 C 구현을 달성하기 위해 루프를 필요 당신이 결정

mov ecx,12 
your_label: 
; your code 
dec ecx 
jnz your_label 
1

을, 어셈블리, 당신을 도울 것입니다 :

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 : (같은 태그가없는 상태) 영업의 코드가 86 동안 eventhelix.com

+3

이 68K 어셈블러 것 같습니다. – user786653

0
.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 
관련 문제