I am in an Assembly language class in college and we are working on assignment that prints data using printf. In class we use Visual Studio Professional 2015 but on my laptop I have Visual Studio Community 2017. In class we change have to change the toolset to a 2013 version but my visual studio does not have that. Here is my code: (it worked perfectly in class but I get errors when running it on my pc):
; Author: Keenan Kaufman
; Date: 9/20/2017
.586
.MODEL FLAT, STDCALL
INCLUDELIB msvcrt.lib
EXTERN printf:NEAR
EXTERN exit:NEAR
.STACK 4096
.DATA
plain BYTE 'Hello, World!'
key BYTE 02h
cipher BYTE SIZEOF plain DUP(?)
.CODE
main PROC
sub eax, eax ; clear registers
sub ebx, ebx
sub ecx, ecx
mov ebx, 0 ; index into strings
mov ecx, SIZEOF plain ; number of chars in strings
lea esi, plain
lea edi, cipher
COPYCHAR:
mov al, [esi]
add al, key
mov [edi], al
inc esi
inc edi
loop COPYCHAR
lea eax, cipher
push eax
call printf ; call printf C function
add esp, 4 ; clean up stack
mov eax, 0 ; exit with
call exit ; return code 0
main ENDP
END
Any help would be appreciated! Thank You!
Related
I am using visual studio for assembly coding and I am pretty new to assembly. My problem is when I assign a number to a register the value of the number is changed.
.386
.model flat, stdcall
stack 4096
ExitProcess PROTO, dwExitCode: DWORD
.data
;define your variables here
adword DWORD ?
aword WORD 7788h
.code
main PROC
mov eax,11223344h ; moved a constant into a register
mov ebx, eax ; moved ebx -> eax
mov adword, eax ; mov eax-> adword
mov ax, aword ; 7788h -> ax
mov ah, 10h
INVOKE ExitProcess, 0
main ENDP
END main
The value of Eax is not 11223344 it becomes something else.
This is my code, the program runs fine when I define the third variable as cc, if and when I change it to C, the variable turns blue (indicating that it is a keyword in the assembly language since I have the .dat file installed to highlight assembly language keywords) the debugger gives me an error of ...\Irvine\Examples\ch03\AddSums.asm" exited with code 1.
I have ran the code through breakpoints in the first case too. Everything is good. I am just concerned since this is an assignment for school and the variable needs to be C, why is it not letting me?
.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.data
A DWORD 30
B DWORD 20
cc DWORD 10
D DWORD 5
.code
main PROC
mov eax, A
mov ebx, B
mov ecx, cc
mov edx, D
add eax, ebx
add ecx, edx
sub eax, ecx
mov A, eax
INVOKE ExitProcess, 0
main ENDP
END main
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
.data
bigEndian byte 12h,34h,56h,78h
littleEndian dword ?
.code
main proc
mov ah,byte ptr bigEndian ; high byte
mov al,byte ptr bigEndian+1 ; 2nd byte
mov word ptr littleEndian+2,ax ; high word
mov ah,byte ptr bigEndian+2 ; 3rd byte
mov al,byte ptr bigEndian+3 ; 4th byte
mov word ptr littleEndian,ax ; low word
invoke ExitProcess,0
main endp
end main
First time using VS2013 and I cannot figure out why this will not run. It tells me in the bottom console 1 fail and a pop-up states "Unable to start program"
Look at the error page, when that error pop-up appears it means that you have not set-up Visual Studio correctly. In this case, the Kip Irvine was no downloaded and that there was no space in the Handlers section in setup.
Comment #
Using Programming Exercise 6 in Chapter 4 as a starting point,
write a program that generates the first 47 values in the Fibonacci
series, stores them in an array of doublewords, and writes the
doubleword array to a disk file.
#
INCLUDE c:\Irvine\Irvine32.inc
FIB_COUNT = 47 ; number of values to generate
.data
fileHandle DWORD ?
filename BYTE "fibonacci.bin",0
array DWORD FIB_COUNT DUP(?)
.code
main2sub PROC
; Generate the array of values
mov esi, OFFSET array
mov ecx, LENGTHOF array
call generate_fibonacci
; Create the file, call CreateOutputFile
mov edx,OFFSET filename
call CreateOutputFile
mov fileHandle, eax
; Write the array to the file, call WriteToFile
mov eax, fileHandle
mov edx, OFFSET array
mov ecx, FIB_COUNT * 4
call WriteToFile
; Close the file, call CloseFile
mov eax, fileHandle
call CloseFile
exit
main2sub ENDP
;------------------------------------------------------------
generate_fibonacci PROC USES eax ebx ecx edx
;
; Generates fibonacci values and stores in an array.
; Receives: ESI points to the array,
; ECX = count
; Returns: nothing
;------------------------------------------------------------
mov ebx, 1
mov ecx, 0
L1:
add ebx, ecx
mov [esi], eax
call WriteDec
call Crlf
inc esi
xchg ebx, eax
loop L1 ;end of looping
ret
generate_fibonacci ENDP
END main2sub
It is my first semester learning about Assembly Language. Im not sure what to do with this error message "fatal error LNK1120: 1 unresolved externals". Can anyone help me out?
The linker couldn't find the library-files Irvine32.lib, Kernel32.Lib and/or User32.Lib. They are in the same folder as Irvine32.inc
The easiest way is to inform ML about those libraries with a MASM-directive. Insert following three lines right behind the INCLUDE c:\Irvine\Irvine32.inc:
INCLUDELIB c:\Irvine\Irvine32.lib
INCLUDELIB c:\Irvine\Kernel32.lib
INCLUDELIB c:\Irvine\User32.lib
I tried this code (using interruptions), but it is for DOS:
mov eax, 42 ; write 42 to console
mov ecx, 10 ; in decimal
out_int_loop:
xor edx, edx
div ecx
push eax
add dl, '0' ; one digit
mov ah, 2 ; 2 is code for writing character
int 21h
pop eax
cmp eax, 0
jnz out_int_loop
I used WriteConsoleA function from winapi.
Also I used GetStdHandle to get stdout.
To import this functions you need these lines:
extern __imp__GetStdHandle#4
extern __imp__WriteConsoleA#20