News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

If you know how to use Visual Studio and Irvine's resources for masm, help me!

Started by RedSkeleton007, February 03, 2016, 06:55:53 PM

Previous topic - Next topic

hutch--

Hi Red,

Here is a toy for you. You can display all 8 registers in console mode in MASM32 without needing the Irvine version.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .data?
      value dd ?

    .data
      item dd 0

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    call reg_status

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

reg_status PROC

    .data?
      eax_ dd ?
      ebx_ dd ?
      ecx_ dd ?
      edx_ dd ?
      esi_ dd ?
      edi_ dd ?
      ebp_ dd ?
      esp_ dd ?
    .code

    mov eax_, eax
    mov ebx_, ebx
    mov ecx_, ecx
    mov edx_, edx
    mov esi_, esi
    mov edi_, edi
    mov ebp_, ebp
    mov esp_, esp
    sub esp_, 4

    print "eax = "
    print hex$(eax_),"h",13,10

    print "ebx = "
    print hex$(ebx_),"h",13,10

    print "ecx = "
    print hex$(ecx_),"h",13,10

    print "edx = "
    print hex$(edx_),"h",13,10

    print "esi = "
    print hex$(esi_),"h",13,10

    print "edi = "
    print hex$(edi_),"h",13,10

    print "ebp = "
    print hex$(ebp_),"h",13,10

    print "esp = "
    print hex$(esp_),"h",13,10

    ret

reg_status ENDP

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start


Output will look something like this.


eax = 749A3378h
ebx = 7EFDE000h
ecx = 00000000h
edx = 00401000h
esi = 00000000h
edi = 00000000h
ebp = 0018FF94h
esp = 0018FF80h
Press any key to continue ...

hutch--

Here is a normal UI version that shows a MessageBox.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    .data?
      value dd ?

    .data
      item dd 0

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    call showregs

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

showregs PROC

    LOCAL buffer[256]:BYTE
    LOCAL pbuf  :DWORD

    .data?
      eax_ dd ?
      ebx_ dd ?
      ecx_ dd ?
      edx_ dd ?
      esi_ dd ?
      edi_ dd ?
      ebp_ dd ?
      esp_ dd ?
    .code

    mov eax_, eax
    mov ebx_, ebx
    mov ecx_, ecx
    mov edx_, edx
    mov esi_, esi
    mov edi_, edi
    mov ebp_, ebp
    mov esp_, esp
    sub esp_, 4

    mov pbuf, ptr$(buffer)

    mov pbuf, cat$(pbuf,"eax   =   ",hex$(eax_),"h",chr$(13,10),"ebx   =   ",hex$(ebx_),"h",chr$(13,10))
    mov pbuf, cat$(pbuf,"ecx   =   ",hex$(ecx_),"h",chr$(13,10),"edx   =   ",hex$(edx_),"h",chr$(13,10))
    mov pbuf, cat$(pbuf,"esi   =   ",hex$(esi_),"h",chr$(13,10),"edi   =   ",hex$(edi_),"h",chr$(13,10))
    mov pbuf, cat$(pbuf,"ebp   =   ",hex$(ebp_),"h",chr$(13,10),"esp   =   ",hex$(esp_),"h",chr$(13,10))

    fn MessageBox,0,pbuf,"Registers",MB_OK

    ret

showregs ENDP

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start

dedndave

use PUSHAD to set up the stack frame   :P

;----------------------------------------

_reg_eax TEXTEQU <DWORD PTR [EBP+32]>
_reg_ecx TEXTEQU <DWORD PTR [EBP+28]>
_reg_edx TEXTEQU <DWORD PTR [EBP+24]>
_reg_ebx TEXTEQU <DWORD PTR [EBP+20]>
_reg_esp TEXTEQU <DWORD PTR [EBP+16]>
_reg_ebp TEXTEQU <DWORD PTR [EBP+12]>
_reg_esi TEXTEQU <DWORD PTR [EBP+8]>
_reg_edi TEXTEQU <DWORD PTR [EBP+4]>

;----------------------------------------

    pushad
    push    ebp
    mov     ebp,esp

;

    leave
    popad
    ret

dedndave

another version...

;----------------------------------------

_reg_eax TEXTEQU <DWORD PTR [EBP-4]>
_reg_ecx TEXTEQU <DWORD PTR [EBP-8]>
_reg_edx TEXTEQU <DWORD PTR [EBP-12]>
_reg_ebx TEXTEQU <DWORD PTR [EBP-16]>
_reg_esp TEXTEQU <DWORD PTR [EBP-20]>
_reg_ebp TEXTEQU <DWORD PTR [EBP-24]>
_reg_esi TEXTEQU <DWORD PTR [EBP-28]>
_reg_edi TEXTEQU <DWORD PTR [EBP-32]>

;----------------------------------------

    push    ebx
    push    esi
    push    edi
    push    ebp
    mov     ebp,esp
    pushad

;

    leave
    pop     edi
    pop     esi
    pop     ebx
    ret

Zen

Hi, REDSKELETON007, 
We here at the MASM Forum, get these kinds of questions alot. The answer is pretty simple, really,...
I have used Visual Studio over a period of years, for coding numerous C++ and Net Framework (C#) projects. It is a great IDE, but, to use it effectively, you must be aware of how its default mode operates, and, how to alter the various project settings, using the Project Properties Page. Here is the Microsoft MSDN Documentation: Working with Project Properties, MSDN. Unfortunately, when you alter the Project Properties, Visual Studio, saves this data and applies it to ALL PROJECTS that you open.
I've written many projects that compile MASM assembly language DLLs, and incorporate them with a C++ Visual Studio Project. This is not the default mode for Visual Studio, and so it doesn't work well to create the entire project with Visual Studio. The best way to do this is to write the source code for MASM assembly language component DLL and then compile it with MASM ml.exe (using the QuickEditor menu selection is the  simplest and easiest way). Then write the rest of your project in C++ and compile it with Visual Studio, keeping the two components separate. Write your assembly language DLL so that it exports its routines, and write your C++ Visual Studio components so that it imports those routines into your Visual Studio project.
...Oh,...and also, the Irvine Library functions are a total pain in the ass,...they are designed so that they only work with other Irvine Library routines. This is a MAJOR source of error for novice MASM programmers.

hanx.leee

Hello
I met this problem somedays ago, and I've already solved it.

TIPs:
If you include Irvine32.inc, DON'T include these code:
.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD

(I don't know why I can't use the Insert Code function. Maybe because this is a new account?)



So try compiling this below. It is from Chapter 5 in Irvine's book


.data
COUNT = 4
BlueTextOnGray = blue + (lightGray * 16)
DefaultColor = lightGray + (black * 16)
arrayD SDWORD 12345678h,1A4B2000h,3434h,7AB9h
prompt BYTE "Enter a 32-bit signed integer: ",0
.code
main PROC
   mov eax,BlueTextOnGray
   call SetTextColor
   call Clrscr

   mov esi,OFFSET arrayD
   mov ebx,TYPE arrayD
   mov ecx,LENGTHOF arrayD
   call DumpMem

   call Crlf
   mov ecx,COUNT
   
L1:   mov edx,OFFSET prompt
   call WriteString
   call ReadInt
   call Crlf

   call WriteInt
   call Crlf
   call WriteHex
   call Crlf
   call WriteBin
   call Crlf
   call Crlf
   loop L1
   
   call WaitMsg
   mov eax,DefaultColor
   call SetTextColor
   call Clrscr

   exit

main ENDP
END main