News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Formula multiplication table(i code a macro for cout)

Started by debugee, June 12, 2011, 04:13:55 AM

Previous topic - Next topic

debugee

;***************test.asm start********************
.386
.model flat,stdcall
option casemap:none

include      macro.inc
.data
i   dd   1
j   dd   1
.code
start:

   .while   i < 10
      mov   j,1
      mov   ebx,i
      .while   j <= ebx
         mov   eax,ebx
         mul   j
         ;结果在eax中
         ;cout<<j<<"*"<<ebx<<"="<<j*ebx<<"\t"
         cout   j   #"*"   #ebx   #"="   #eax   #table
         inc   j
      .endw
      cout endl
      inc   i
   .endw

   ret
end   start
;********************test.asm ends*****************************
;********************macro.inc start****************************
extrn   printf:near

repargv MACRO arg
   LOCAL nustr
   quot SUBSTR <arg>,1,1
   IFIDN quot,<">            ;; if 1st char = "
      .data
        nustr db arg,0        ;; write arg to .DATA section
      .code
      mov eax, OFFSET nustr
      EXITM <eax>             ;; return data section offset in eax
   ELSE
      mov eax, arg
      EXITM <eax>             ;; else return arg
   ENDIF
ENDM
   
;;过滤空格键
conbreak   macro   $szStr:vararg
      
      szBuf   textequ   <>
      szTemp   textequ   <>
      %echo   ************************************
      forc   qout,<$szStr>

         ifidn   <qout>,< >
         
         else
            szTemp   textequ   <qout>
            szBuf   textequ   @CatStr(<%szBuf>,<%szTemp>)
            %echo   szBuf         
         endif
      endm
      
      exitm   <szBuf>
   
endm

;输出
cout   macro   $string:vararg
   
   LOCAL   fuck
   LOCAL   pStr
   LOCAL   szEndl
   LOCAL   pTemp
   LOCAL   szMakeTab
   
   LOCAL   szDec
   
   
   nNumf = 1
   nNuml = 0
   nNum  = 0
   fuck   textequ   <#>
   
   .data
   szDec      db   '%d',0
   szEndl      db   13,10,0   
   szMakeTab   db   09,0   
      
   forc   qStr,<$string>
      nNuml = nNuml + 1
      ifidn   <qStr>,fuck
         %echo   qStr
         pStr   textequ   %nNumf
         %echo   pStr
         nNum =nNuml - nNumf
         pStr   textequ   @SubStr(<$string>,nNumf,nNum)   
         nNumf = nNuml + 1
         %echo   pStr
         ;***********************************
         pTemp   textequ   pStr
         pTemp   textequ   conbreak(%pTemp)
         %echo   pTemp
         %echo   pStr
         ifidn   <endl>,pTemp
            ;打印一个换行
            .code
               pushad
               push   offset szEndl
               call   printf
               add   esp,4
               popad
         elseifidn <table>,pTemp
            .code
               pushad
               push   offset szMakeTab
               call   printf
               add   esp,4
               popad
               
         else
            pTemp   SUBSTR pStr,1,1
            ifidn   pTemp,<">
               pushad
               push   repargv(%pStr)
               call   printf
               add   esp,4
               popad
            else

               .code
               pushad
               push   pStr
               push   offset szDec
               call   printf
               add   esp,8
               popad

            endif
            ;pStr      ;;输出汇编语句
         endif
         
         ;***********************************
      else
         %echo   qStr
      endif
   endm
   
   nNum =nNuml - nNumf + 1
   pStr   textequ   @SubStr(<$string>,nNumf,nNum)   
   nNumf = nNuml + 1
   %echo   pStr

   ;**********************************************
   ;pStr      ;;输出汇编语句
   ;**********************************************
   pTemp   textequ   pStr
   pTemp   textequ   conbreak(%pTemp)
   %echo   pTemp
   %echo   pStr
   ifidn   <endl>,pTemp
      ;打印一个换行
      .code
         pushad
         push   offset szEndl
         call   printf
         add   esp,4
         popad
   elseifidn <table>,pTemp
      .code
         pushad
         push   offset szMakeTab
         call   printf
         add   esp,4
         popad
   else
      pTemp   SUBSTR pStr,1,1
      ifidn   pTemp,<">
         pushad
         push   repargv(%pStr)
         call   printf
         add   esp,4
         popad
      else
         .code
         pushad
         push   pStr
         push   offset szDec
         call   printf
         add   esp,8
         popad
      endif
      ;pStr      ;;输出汇编语句
   endif
   
   ;***********************************

endm
;*************************ends********************************

jj2007

Windows says the zip file is not a valid archive... but I could open it with 7-zip. It's a rar archive.

The test.asm assembles fine but the linker can't find printf - missing library?

By the way: I see Unicode in your post but in the *asm and *.inc files the Chinese text has become garbage. Which editor do you use?

0x401000

Quote from: jj2007 on June 12, 2011, 06:41:46 AM
Windows says the zip file is not a valid archive... but I could open it with 7-zip. It's a rar archive.


Hi!

With a compressed archive all okay! No errors ..

debugee

hi jj2007
printf function in the msvcrt.lib
you can link the obj file like this:
link msvcrt.lib /subsystem:console xxx.obj

i am chinese ,so the edit is chinese version.