2011-10-06 27 views
0

我只想過簡單的寫.ASM代碼TASM是在C工作對於++TASM簡單的循環FPGA實現

int t=2; 
for(int i=0;i<2;i++) 
t=t+(i-1)*7*t; 

如何我TASM實現它?

+1

請顯示你到目前爲止 – Mat

+0

我只是想知道如何用TASM編程一個簡單的例子...我沒有用TASM寫任何東西 – pooya

+0

它通常被認爲是一種很好的形式首先要問。去谷歌「tasm循環」,看看你可以找出你自己。試試吧。告訴我們它是否有效......然後回到我們身邊。 –

回答

0

從1這將環路100在8086 TASM:

.MODEL SMALL 

    .STACK 100h 

    .DATA 
    Finished DB 10, 13, 'Loop x 100 finished. Congratulations! $', 10, 13 

    .CODE 

    MAIN PROC 

      MOV AX, @data   ; Required at the start of every program (inside your main procedure, from what I've seen) 
      MOV DS, AX 

      MOV CX, 100    ; Set CX to 100 
      MOV BX, 0    ; Counter (for double-verification, I guess...lol) 

    StrtLoop:      ; When a loop starts, it does CX-- (subtracts 1 from CX) 

      INC BX     ; This does BX++, which increments BX by 1 

    LOOP StrtLoop      ; Go back to StrtLoop label 

      CMP BX, 100    ; Compare BX to 100... 
      JE DispMsg    ; Jump-if-Equal...CMP BX, 100 sets flags, and if they are set, 
            ; JE will Jump you to DispMsg (to get "congratulations" message). 

      JMP SkipMsg    ; Jump to the SkipMsg label (so you don't see the "congratulations" message). 

    DispMsg:       ; If BX = 100, you JE here. 
      MOV AH, 09H    ; Displays the message stored in the defined byte "Finished" 
      MOV DX, OFFSET Finished 
      INT 21H 
    SkipMsg:       ; If BX != 100, you JMP here. 
      MOV AL, 0h    ; Op code to exit to DOS from the assembler. 
      MOV AH, 4CH 
      INT 21H 

    MAIN ENDP 
    END MAIN 

我希望它能幫助。我做了基本的循環,所以你可以做你的代碼的其他部分(我不知道C++,哈哈)。祝你好運!這很難,但同時很有趣(至少對我而言)。

+0

順便說一句,DOS函數9不會打印任何超出「$」字符的東西。所以,最後一個CR/LF對是不必要的,或者應該放在「$」之前。 –

+0

好的,謝謝! – SalarianEngineer