Cannot open input file Resources.res - masm

Please help me on this problem i have searched a lot and found no answer when i build any project in MASM64 i get this error
LINK : fatal error LNK1181: cannot open input file 'C:\Users\emad\Desktop\EmadMASM\Win64App\Release\Resource.res'
I have tried many ML64.exe files and rc.exe files and i couldn't solve the problem
I have tried every solution even i have installed new windows but the problem is same
extrn ExitProcess: PROC
extrn MessageBoxA: PROC
includelib user32.lib
includelib kernel32.lib
; *************************************************************************
; Our data section. Here we declare our strings for our message box
; *************************************************************************
.data
strTitle db "64-bit",0
strMessage db "Hello World!",0
; *************************************************************************
; Our executable assembly code starts here in the .code section
; *************************************************************************
.code
WinMainCRTStartup PROC
sub rsp,28h ; shadow space, aligns stack
mov rcx,0 ; hWnd = HWND_DESKTOP
lea rdx,strMessage ; LPCSTR lpText
lea r8,strTitle ; LPCSTR lpCaption
mov r9d,0 ; uType = MB_OK
call MessageBoxA ; call MessageBox API function
mov ecx,eax
call ExitProcess
WinMainCRTStartup ENDP
End

Related

Using extrn prinf:near in MASM

Hello have a MASM assembly question. In the code below:
What is- extrn printf:near
It is refering to prinf function being called externally but what does the :near signify?
; include C libraries
includelib msvcrtd
includelib oldnames
includelib legacy_stdio_definitions.lib ;for scanf, printf, ...
.data
prompt db "Enter a number: ", 0
fmt db "%i", 0
input sdword ?
output byte 'z' ; initialize to 'z' as default
.code
extrn printf:near
extrn scanf:near
public main
main proc
push offset prompt
call printf
add sp,4
; get input with scanf
push offset input
push offset fmt
call scanf
add sp, 8
cmp input, 0
je LOUTPUT
jg LPOS
jng LNEG
LPOS:
mov output, 'p'
jmp LOUTPUT
LNEG:
mov output, 'n'
jmp LOUTPUT
LOUTPUT:
push offset output
call printf
add sp, 4
ret
main endp
end

How to Open Existing File and Write to File (Overwrite contents) in assembly language MASM , irvine32 bits

the problem focuses on MASM and using Irvine 32 bits only. I don't plan to use macro or etc unless really needed.
.386
.model flat, stdcall
INCLUDE Irvine32.inc
.stack 4096
.Data
inputFilename byte "Enter filename : ",0
errorMssg byte "Unable to open file !",0
newAmount byte "2021",0 ;updated from dword to byte
fileHandle HANDLE ?
buffer dword 200 DUP(?)
.Code
main PROC
I would like to prompt user enter a filename. Then Open the file if it exist, if not error message is display. Lets assume the file is created and therefore exist. In the file contains just a number which is 2020.
OPEN_EXISTING_FILE:
mov edx,offset inputFilename ;ask user enter the existing filename
;currently in existing file content is 2020
call WriteString
call Crlf
mov ecx, SIZEOF inputFilename
call ReadString
call OpenInputFile
mov fileHandle,eax
;file error check
cmp eax, INVALID_HANDLE_VALUE
jne OVERWRITE_FILE
mov edx, offset errorMssg
call WriteString
call Crlf
jmp OPEN_EXISTING_FILE
It seems my Write to File is not working. Am i missing some codes? Can anyone guide me on how can i replace the "2020" to "2021", in the file.
OVERWRITE_FILE:
mov eax,fileHandle
mov edx, OFFSET newAmount ;i want to overwrite 2020 to 2021 in the existing file
mov ecx, LENGTHOF newAmount
call WriteToFile
call CloseFile
call crlf
call waitMsg
END main

Assembly NASM x86 - Putting char into array

I need to make a program that open a file, read it character by character and save it into an array in Assembly NASM x86. Currently, the program is able to open a file using stdin and read the character by using getchar(). However, i am stuck on the saving the char into an array and need help on this part.
Thank you
; Run it this way:
; test < (input file)
; Build using these commands:
; nasm -f elf -g -F stabs test.asm
; gcc –m32 -o test.o test
;
SECTION .bss ; Section containing uninitialized data
TextLenght EQU 1024 ; Define length of a line of text data
Text resb TextLenght ; Define array
SECTION .data ; Section containing initialised data
fileFmt: db "%c",0
SECTION .text ; Section containing code
extern putchar
extern getchar
extern printf
global main; Linker needs this to find the entry point!
main :
start:
nop ; This no-op keeps gdb happy...
mov eax, 0
mov edx, 0
mov ecx, 0
mov ebx, 0
; Read a buffer full of text from stdin:
read:
call getchar ; call getchar to get input from stdin, char is save in eax
cmp al, -1
jle Done ; if return -1, we at EOF
cmp eax, 97 ; get rid of 'enter' char
jl read
;mov Text, eax; try to save char in eax into array, don;t work
push eax ;push eax to print
push fileFmt
call printf
add esp, 8 ; clear the stack
jmp read
Done:
mov eax,1 ; Code for Exit Syscall
mov ebx,0 ; Return a code of zero
int 80H ; Make sys_exit kernel call

Assembly of C code is not understood?

I have written a simple c code in visual studio. Here is the code ..
#include<stdio.h>
int global;
int onemore=5;
int main(){
int local;
static int slocal;
return 0;
}
and here is it's assembly after compiling in visual studio ..
; Listing generated by Microsoft (R) Optimizing Compiler Version 15.00.21022.08
TITLE c:\Users\amit_bhaira\Documents\Visual Studio 2008\Projects\AssOneQuestion1\AssOneQuestion1\question1.c
.686P
->.XMM
->include listing.inc
->.model flat
->INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES
PUBLIC _onemore
_DATA SEGMENT
COMM _global:DWORD
_onemore DD 05H
_DATA ENDS
PUBLIC _main
->EXTRN__RTC_Shutdown:PROC
->EXTRN__RTC_InitBase:PROC
; COMDAT rtc$TMZ
; File c:\users\amit_bhaira\documents\visual studio 2008\projects\assonequestion1\assonequestion1\question1.c
rtc$TMZ SEGMENT
->__RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown
rtc$TMZ ENDS
; COMDAT rtc$IMZ
rtc$IMZ SEGMENT
__RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase
; Function compile flags: /Odtp /RTCsu /ZI
rtc$IMZ ENDS
; COMDAT _main
_TEXT SEGMENT
_main PROC ; COMDAT
; 4 : int main(){
push ebp
mov ebp, esp
sub esp, 204 ; 000000ccH
->push ebx
->push esi
->push edi //why these(ebx,esi and edi) registers are pushed into the stack ??
lea edi, DWORD PTR [ebp-204]
mov ecx, 51 ; 00000033H
mov eax, -858993460 ; ccccccccH
rep stosd
; 5 : int local;
; 6 : ->static int slocal;
; 7 : return 0;
xor eax, eax
; 8 : }
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
_main ENDP
_TEXT ENDS
END
I have put an arrow(->) in front of the lines that I didn't get. So please explain them.
Though I have taken a static variable inside the main method but no special steps are taken by the
compiler, what is that suppose to mean. Static varialbe is also going to be handled like other local
variable, no special storage for static variable. If Yes then how is the memory of static variable is preserved for the next function call ??

how to call C functions from assembly routines and link the C and assembly files using nasm and gcc

I want to call at least 1 C function from assembly. It is because I'm doing my own tiny OS from scratch(out of nothing). The reason i want to call c function from my boot loader. I can understand assembly but poor in writing my own program. So if i could transfer control from assembly procedure to c procedure my job is made easier.
So how to link assembly pgm and C program files into one. It is ok for me even if the file size exceeds 512 bytes.
I am doing this on Windows 7 with help of mingw. my c compiler is gcc and assembler is nasm.
easier to just show you an example, I found this on the internet a while ago and saved it as a source on my computer, not sure where from though
; printf1.asm print an integer from storage and from a register
; Assemble: nasm -f elf -l printf.lst printf1.asm
; Link: gcc -o printf1 printf1.o
; Run: printf1
; Output: a=5, eax=7
; Equivalent C code
; /* printf1.c print an int and an expression */
; #include
; int main()
; {
; int a=5;
; printf("a=%d, eax=%d\n", a, a+2);
; return 0;
; }
; Declare some external functions
;
extern printf ; the C function, to be called
SECTION .data ; Data section, initialized variables
a: dd 5 ; int a=5;
fmt: db "a=%d, eax=%d", 10, 0 ; The printf format, "\n",'0'
SECTION .text ; Code section.
global main ; the standard gcc entry point
main: ; the program label for the entry point
push ebp ; set up stack frame
mov ebp,esp
mov eax, [a] ; put a from store into register
add eax, 2 ; a+2
push eax ; value of a+2
push dword [a] ; value of variable a
push dword fmt ; address of ctrl string
call printf ; Call C function
add esp, 12 ; pop stack 3 push times 4 bytes
mov esp, ebp ; takedown stack frame
pop ebp ; same as "leave" op
mov eax,0 ; normal, no error, return value
ret ; return

Resources