首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TASM简单循环实现

TASM简单循环实现
EN

Stack Overflow用户
提问于 2011-10-07 05:24:52
回答 1查看 11.3K关注 0票数 0

我只想为在C++中工作的TASM编写简单的.asm代码

代码语言:javascript
复制
int t=2;
for(int i=0;i<2;i++)
t=t+(i-1)*7*t;

我如何用TASM实现它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-28 06:29:15

这将在8086 TASM中从1循环到100:

代码语言:javascript
复制
    .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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7680631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档