0
点赞
收藏
分享

微信扫一扫

汇编实现 hello world

腾讯优测 2022-03-27 阅读 50
开发语言

1.利用RadASM 写汇编程序

    本文介绍利用RedASM写一个messageBox “hello world”.

 .386
 .model flat, stdcall
 option casemap :none
  
 include windows.inc
 include kernel32.inc
 include masm32.inc 
 includelib kernel32.lib
 includelib masm32.lib
 
 .data
     helloWorld db "hello world",0
     
 .code
     start:
         invoke StdOut, addr helloWorld
         invoke ExitProcess,0
     
     end start

2.习题:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 
写成c代码很简单: 

void p1_fun()

{

    for (int i = 1; i <= 4; ++i){

        for (int j = 1; j <= 4; ++j){

            for (int k = 1; k <=4; ++k){

                if (i !=j && i !=k && j != k){

                    ostringstream stringStream;

                    stringStream<<i<<j<<k;

                    cout<<stringStream.str()<<",";

                }

            }

        }

    }

}

  用汇编实现如下

Title: Hello world

 ;Author: sld6666666@gmail.com   

 ;Data: 2012-11-29

 ;Description: Assemble hello world

 .386                ;¸Ã³ÌÐò¶ÔCPUµÄ×îµÍÒªÇóÊÇintel 386

 .model flat, stdcall        ; ƽ̹ÄÚ´æÄ£ÐÍ£¬ stacll º¯Êýµ÷Ó÷½Ê½

 .stack 4096            ;Õ»µÄ´óСΪ4096B

 option casemap:none

  

 ;include Í·Îļþ£¬ Á¬½Ó¿â

include msvcrt.inc

includelib msvcrt.lib

  

 .data                    ;Êý¾Ý¶Î

     index_0 dd  dword

     index_1 dd  dword

     index_2 dd  dword

     szFmt db '%d%d%d', 0

     entryFmt db '  ',0

  

 .code

     start:

        mov index_0, 0

      

        forProcess_0:

            cmp index_0, 5

            jge rtnProcess 

            inc index_0

            mov index_1, 0

             

            forProcess_1:

                cmp index_1, 5

                jge forProcess_0

                inc index_1

                mov index_2, 0

                 

                forProcess_2:

                    cmp index_2, 5

                    jge forProcess_1

                    inc index_2

                     

                    mov eax, index_0

                    mov ebx, index_1

                    mov edx, index_2

                     

                    cmp eax, ebx

                    je forProcess_2

                     

                    cmp eax, edx

                    je forProcess_2

                     

                    cmp ebx, edx

                    je forProcess_2

                     

                    invoke crt_printf, addr szFmt,eax, ebx, edx

                    invoke crt_printf, addr entryFmt

                    jmp forProcess_2

        rtnProcess:

            ret

      

     end start

举报

相关推荐

0 条评论