0

C ++と同じように機能するTASM用の単純な.asmコードを書きたいだけです

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

TASM で実装するにはどうすればよいですか?

4

1 に答える 1

0

これは、8086 TASM で 1 から 100 までループします。

    .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++ はわかりませんが、笑)。幸運を!難しいですが、同時に楽しいです(少なくとも私にとっては)。

于 2012-04-27T22:29:15.467 に答える