GunnerInc 7 xor eax, eax Team Colleague

How would you fix it if you wanted the entry point of your program to be NewbieChameleon? You would use the -e or --entry command line option for ld:

-eEntryPointLabel
--entry=EntryPointLabel

I use a makefile and used this for an example and 64bit O:
ld -o $(APP) $(APP).o -melf_i386 -eNewbieChameleon -dynamic-linker /lib/ld-linux.so.2

GunnerInc 7 xor eax, eax Team Colleague

First thing, arraylen does not contain what you think. It contains 20: 5 dword sized elements. To get the number of elements divide by 4

arraylen equ ($ - array) / 4

Next, you cannot print a number, you first need to convert it to ASCII. For your elements it is simple (since they are single digits), add 48 to each element (for numbers > 9 it is a bit different).

Here is some code to get you going:

%include '../../include/syscalls32.inc'

section .bss

section .data

    array dd 1,2,3,4,5

    arraylen equ ($ - array) / 4            ; array length * 4 = number of elements

section .text

    global _start:

_start:

    mov     esi, array                      ; get pointer to array
    mov     edi, arraylen - 1               ; edi = number of array elements

.PrintArray:
    mov     edx, 1                          ; print 1 byte                 
    mov     ecx, [esi]                      ; get current array element
    add     ecx, 48                         ; add 48 to convet to ASCII
    push    ecx                             ; push to stack since we need an address of item to print
    mov     ecx, esp                        ; mov address of char to ecx
    mov     ebx, stdout
    mov     eax, sys_write
    int     80h                             ; now print it
    pop     ecx                             ; balance stack
    add     esi, 4                          ; get next element, 4 because it's an array of dwords
    dec     edi                             ; decrease loop counter
    jns     .PrintArray                     ; if edi ! -1 continue loop

.PrintLineFeed:
    sub     esp, 4
    mov     byte [esp], 10
    mov     edx, 1
    mov     ecx, esp
    mov     ebx, stdout
    mov     eax, sys_write
    int     80h
    add …
GunnerInc 7 xor eax, eax Team Colleague

You need to install the 32 bit libraries:
ia32-libs
or
ia32-libs-multiarch
With your package manager or:

sudo apt-get install ia32-libs

GunnerInc 7 xor eax, eax Team Colleague

It really is not hard at all to use libcurl. You read the docs pass some parameters and call the functions. The following simple code will get googles robots.txt file and display it in the terminal.

It is 64-bit using NASM tested on Linux

%define CURL_GLOBAL_SSL (1<<0)
%define CURL_GLOBAL_WIN32 (1<<1)
%define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32)
%define CURL_GLOBAL_NOTHING 0
%define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL

%define CURLOPT_URL 10002
%define CURLOPT_FOLLOWLOCATION 52
%define CURLOPT_WRITEHEADER 10029
%define CURLOPT_WRITEDATA 10001

extern curl_easy_init, curl_easy_cleanup, curl_easy_setopt, curl_easy_perform
extern curl_global_init, curl_global_cleanup

extern exit, stdout

section .data
url         db  "http://www.google.com/robots.txt", 0

global main
section .text
main:

    mov     rdi, CURL_GLOBAL_ALL
    call    curl_global_init

    call    curl_easy_init
    mov     r15, rax

    mov     rdx, url
    mov     rsi, CURLOPT_URL
    mov     rdi, r15
    xor     rax, rax
    call    curl_easy_setopt

    mov     rdx, 1
    mov     rsi, CURLOPT_FOLLOWLOCATION
    mov     rdi, r15
    xor     rax, rax
    call    curl_easy_setopt

    mov     rdx, [stdout]
    mov     rsi, CURLOPT_WRITEDATA
    mov     rdi, r15
    xor     rax, rax
    call    curl_easy_setopt

    mov     rdi, r15
    call    curl_easy_perform

    mov     rdi, r15
    call    curl_easy_cleanup

    call    curl_global_cleanup

    mov     rdi, 0
    call    exit

Error handling/checking has been left out.

and the makefile:

APP=download_file

all: $(APP) clean

$(APP): $(APP).o
    gcc -g -o $(APP) $(APP).o -lcurl

$(APP).o: $(APP).asm
    nasm -f elf64 $(APP).asm -F dwarf

clean:
    rm $(APP).o
GunnerInc 7 xor eax, eax Team Colleague

Nobody is taught to use comments anymore? It is so important to comment your code in Assembly, ESPECIALLY in ancient 16bit code where functions don't have names but numbers!!

Your getting weird characters because after you get the input character, you are modifying it by adding 20h to dl.

To print each letter on a new line, you need to add a call to your nlcr in your y loop, but you must also save the register dx

This should get you started:

 main proc
        mov     ax,@data
        mov     ds, ax

        mov     ah, 9
        lea     dx, string
        int     21h

        call    nlcr

        mov     ah, 9
        lea     dx, string2
        int     21h

        mov     ah, 1       ; get user input
        int     21h
        mov     dl, al

        call    nlcr        ; print CRLF 

        mov     cx, 25      ; print 25 chars in loop
        inc     dl          ; adjust to print input char on 1st iteration
    PrintChar:
        mov     ah, 2       ; print char
        dec     dl
        int     21h

        call    nlcr        ; print CRLF

        loop    PrintChar   ; repeat loop until cx == 0

        mov     ah, 4ch     ; goodbye
        int     21h
    main endp

    nlcr proc
        push    dx          ; save dx since dl contains char to print

        mov     ah, 2
        mov     dl, 13
        int     21h

        mov     dl, 10
        int     21h

        pop     dx          
        ret
    nlcr endp
GunnerInc 7 xor eax, eax Team Colleague

Your program starts executing at the start label and goes right to the WinProc, this won't work since you have not registered the window class yet.
Move this:

    invoke GetModuleHandle, NULL
    mov hInstance, eax
    invoke WinMain, hInstance, NULL, NULL, 0
    invoke ExitProcess, eax

from the end to right after start:

Your DestryWindow call is wrong, you are passing the address of hWnd and not the value, remove addr.
Your calling ShowWindow with CmdShow and you are passing 0 for that parameter in your call to WinMain. ShowWindow is not needed if you creat the window with WS_VISIBLE.

You also need a ret after your STOP label otherwise strange things will happen. Here is the corrected code in which the window will show and close properly.

.386
.model flat, stdcall
option casemap :none 

include \masm32\include\windows.inc 
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib


WinMain PROTO :HINSTANCE, :HINSTANCE, :LPSTR, :DWORD
WinProc PROTO :HWND, :UINT, :WPARAM, :LPARAM

.data
    ClassName   db "MAIN_CLASS", 0
    MainTitle   db "A Window in Assembly!", 0
    ErrorText   db "Fatal Error, the program will now close...", 0
    ErrorTitle  db "Fatal Error", 0

.data?
    hInstance   HINSTANCE ?

.code
start:
    invoke GetModuleHandle, NULL
    mov hInstance, eax
    invoke WinMain, hInstance, NULL, NULL, 0
    invoke ExitProcess, eax
    WinProc PROC hWnd:HWND, message:UINT, wParam:WPARAM, lParam:LPARAM
            cmp message, WM_DESTROY
            je DO_DESTROY

            cmp message, WM_CLOSE
            je DO_CLOSE

            jmp DO_DEFAULT

            DO_DESTROY:

            invoke PostQuitMessage, 0
            jmp DO_END

            DO_CLOSE:

            invoke DestroyWindow,  hWnd
            jmp DO_END

            DO_DEFAULT:

            invoke DefWindowProc, hWnd, message, wParam, lParam
            ret 

            DO_END:

            xor eax, eax
            ret

    WinProc …
GunnerInc 7 xor eax, eax Team Colleague

It is a false positive. The package is created on clean machine not connected to the internet. Get a better AV.

GunnerInc 7 xor eax, eax Team Colleague
GunnerInc 7 xor eax, eax Team Colleague

What do you think the answer to no.1 is?
The answer to no.2 is in the AMD and INTEL manuals of course and plenty of docs on the net.
Do you know what a "register" is? All it is, is memory directly on the CPU die, which makes it the fastest memory to access.

sDJh commented: nothing more to add +0
GunnerInc 7 xor eax, eax Team Colleague

That is all great, so since you didn't meantion what Assembler, I will give you code that you could assemble with say YASM.

DOSBox? That means 16 bit code. Why oh why on earth do you want to use that? That is DEAD, let it rest in peace!! Learn 32bit code!!!!

Do you have any idea how it should be implemented or you just didn't pay attention in class?

You say you are "trying" to write a program, this means you have started coding and are stuck? Show us the code you have so far.

GunnerInc 7 xor eax, eax Team Colleague

Maybe. What OS? Which Assembler?

"Do you want fries with that?"

GunnerInc 7 xor eax, eax Team Colleague

You will never compile it! You Assemble and Link.

Your stack is a MESS! Your pushes are not paired with pops. For every push you should have a pop or adjust esp manually.

where is this address > 0xb7? Why use a hardcoded address? use a label.

It won't print anything really. for the sys_write system call, ecx is a pointer to the string to write to the terminal NOT a character.

What does it do anyways?

GunnerInc 7 xor eax, eax Team Colleague

You don't need many buffers. You have one buffer for your input right? That is all you need. Write a conversion function (or find one on the net, but you will better yourself writing it on your own) that takes a pointer to your input buffer, and goes thourgh each character in your buffer, converts them all and returns the integer in eax.

GunnerInc 7 xor eax, eax Team Colleague

Go to preferences and select the terminal tab.
Uncheck "Follow the path of the current file"
Check "Don't use run script"
and to use the Geany terminal, check "Execute programs in VTE"

GunnerInc 7 xor eax, eax Team Colleague

They are macros to make life easier. Most x86 Assemblers have if/endif, while etc...

GunnerInc 7 xor eax, eax Team Colleague

What does "I can't run my program" mean? What errors are you getting? Why are you using an emulator? Do you not have an INTEL PC?

GunnerInc 7 xor eax, eax Team Colleague

2 things:
1. All of this code:

FullVertWait:
        mov   dx,3dah
vr:
        in    al,dx
        test  al,8
        jnz   vr                                 ; wait until Vertical Retrace starts
nvr:
        in    al,dx
        test  al,8
        jz    nvr                                ; wait until Vertical Retrace Ends
    add word[count1],1
    add eax,0
        ret
Delay:
       mov   word[count1],0
ddf:
       call  FullVertWait
       cmp   word [count1],700                   ; 70 = 1 second,so this = 10 seconds
       jne   ddf
       ret

HAS TO BE in your code section NOT the data section!!!!
2. Use the Sleep or SleepEx API

also, you cannot use privilaged instructions in user mode. IN is a privilaged instruction.

GunnerInc 7 xor eax, eax Team Colleague

What is the lea instruction? And how does that translate to NASM?

there is no translation. It is a CPU mneumonic on x86 it means load effective address

GunnerInc 7 xor eax, eax Team Colleague

Yes, and also when writing an OS/boot loader. Unless a newbie is going to write an OS, they are better off at the beginning to skip 16bit unless they really need it, it is a PITA to learn verses 32bit.

GunnerInc 7 xor eax, eax Team Colleague

Yes there IS a really BIG difference writing 64bit Assembly code verses 32bit code. Especially when it comes to Windows Programming (I am sure Linux is the same). You have a different calling convention, "shadow space", more memory addresses, more registers, stack should be/has to be aligned.

Learn 32bit first to get a firm understanding of how memory, cpu, program flow works. Then lean 64bit, skip 16bit it is dead.

GunnerInc 7 xor eax, eax Team Colleague

Well, if you like MASM take a look at JWASM. It is fully MASM compatable (Meaning if you have an app written in MASM, JWASM will Assemble it without many complaints) Plus, it is 64bit compatible AND cross-platform

GunnerInc 7 xor eax, eax Team Colleague

Right above the editor to enter a reply, you should see something like:

Has this thread been answered?
If this thread has been successfully resolved, please Mark this Thread as Solved so that it can be added to our Knowledge Base and help others. Also, posters who replied appreciate knowing that they were helpful.

GunnerInc 7 xor eax, eax Team Colleague

My code that I posted works just fine:

10010000000100000000100111010011b (iPanda.asm, 12)
di = 8 (iPanda.asm, 31)

10010001100100011001100111010011b (iPanda.asm, 12)
di = 3 (iPanda.asm, 31)

10000000000000000000000000000001b (iPanda.asm, 12)
di = 30 (iPanda.asm, 31)

10000000000000000000000000000000b (iPanda.asm, 13)
di = 31 (iPanda.asm, 32)

00000000000000000000000000000001b (iPanda.asm, 13)
di = 31 (iPanda.asm, 32)

00000000001000000000000000000001b (iPanda.asm, 13)
di = 20 (iPanda.asm, 32)

10010001100100011001100111010011b (iPanda.asm, 13)
di = 3 (iPanda.asm, 32)

10010001100000011001100111010011b (iPanda.asm, 13)
di = 6 (iPanda.asm, 32)

Shr moves the least significant bit into CF either 1 or 0

How are you using the code and where? Are you adding it right after

notZero:

    shr a,1

jc notZero

because that is NOT needed, the code I posted does not need that.

GunnerInc 7 xor eax, eax Team Colleague

Logic is a bit wrong.
No need for the variables biggest or counter. si = counter and di = biggest

This should work:

mov     cx, 32

NextOne:
    shr     a, 1
    jnc     ItsZero
    mov     si, 0
    jmp     Next
    
ItsZero:
    inc     si
    cmp     si, di
    jbe     Next
    mov     di, si
    
Next:
    dec     cx
    jnz     NextOne     

    ; display result in di here
GunnerInc 7 xor eax, eax Team Colleague

Think of your matrix like this:
it does not look like this in memrory

1 2 3
 4 5 6
 7 8 9

it looks like: 1 2 3 4 5 6 7 8 9 (spaces added for clarity)

So, load the array, print the first number then add 3 to the address print number, add 3 to the address and print number, print next 2 numbers, subtract 3 and print number, subtract 3 again and print number, sub 1 print number, sub 1 and print final number...

GunnerInc 7 xor eax, eax Team Colleague

Actually, you cannot run Turbo C or any DOS programs in Windows 7 and above as DOS is dead an not included in any current version of Windows. If you really want to use Turbo C with Windows 7, then you should download a DOS Emulator such as DosBox or better yet, use the a good frontend to DoxBox like D-Fend which included DosBox http://dfendreloaded.sourceforge.net/

GunnerInc 7 xor eax, eax Team Colleague

Works for me:

1,1,1,1
2,2,2,2
3,3,3,3
4,4,4,4
5,5,5,5

:-)

You are telling WriteFile to write 40 bytes (your buffer size) so it will write what you grab from the console, write them to file then write nulls.

That second CreateFile is NOT needed! You already created the file, and have a handle to the file.
change your WriteFiles to:

invoke  Str_length, addr buffer
    INVOKE  WriteFile,		; write text to file
            fileHandle,		; file handle
            ADDR buffer,		; buffer pointer
            eax,		; number of bytes to write
            ADDR bytesWritten,	; number of bytes written
            0
GunnerInc 7 xor eax, eax Team Colleague

Eh, Not sure, I am an x86 guy - sorry. Check the ARM website for debug stuff you can use.

GunnerInc 7 xor eax, eax Team Colleague

Usually the value is returned in R0. So in your sumR, after you do your stuff, place what you want myvar to equal in R0

GunnerInc 7 xor eax, eax Team Colleague

What Assembler? In MASM

MyInt           DWORD   3
MyIntPointer    DWORD MyInt
mov      eax, MyIntPointer
   mov      eax, [eax]
   PrintDec eax
GunnerInc 7 xor eax, eax Team Colleague

Sounds similar to a question asked here before in this thread.

http://www.daniweb.com/software-development/assembly/threads/386136

my reply is there also :)

GunnerInc 7 xor eax, eax Team Colleague

Few things, why do folks who use Irvine, not use the correct case for the function calls? There is no such function as CRLF, instead it is Crlf. I don't know how the Irvine users don't get errors when Assembling!

Put your 2 buffers in the uninitialized data section - .data?
StringSize - we don't need it, why? ReadString returns the size of the string it reads in.

.data
pleaseEnter 	BYTE 'Please enter your name: ', 0
yourName	BYTE 'Hello, ', 0
reverseName 	BYTE 'Here is your name backwards: ', 0

.data?
StringName 	BYTE 30 DUP (?)
StringReversed	BYTE 30 dup (?)

.code
main PROC

    mov 	edx, OFFSET pleaseEnter
    call 	WriteString 
    
    mov 	edx, OFFSET StringName 
    mov 	ecx, SIZEOF StringName - 1

    call 	ReadString
    mov		ecx, eax     ; <<<<<<<<<<<<<< save the string length
    
    call 	Crlf
    mov 	edx, OFFSET yourName
    
    call 	WriteString
    mov 	edx, OFFSET StringName
    
    call 	WriteString
    call 	Crlf
    call 	Crlf
    
    mov 	edx, OFFSET reverseName
    call 	WriteString 

    lea		esi, StringName
    lea		edi, StringReversed
    dec		ecx ; <<<<<<<<<<<<<< Decrease the counter

@@:
    test	ecx, ecx
    js		Done	; <<<<<<<<<<<<<<  are we below zero?
    mov		al, byte ptr [esi + ecx] ; <<<<<<<<<<<<<< move the char in esi to al
    mov		byte ptr [edi], al ; <<<<<<<<<<<<<< now move into edi
    inc		edi ; <<<<<<<<<<<<<< increase pos of edi
    dec		ecx ; <<<<<<<<<<<<<<  decrease our counter
    jmp		@B ; <<<<<<<<<<<<<< reverse next char
    
Done:
    mov		edx, offset StringReversed
    call	WriteString
    call 	Crlf
    call	WaitMsg ; <<<<<<<<<<<<<< good to have so you …
GunnerInc 7 xor eax, eax Team Colleague

Where is the rest of the code?

Nevermind

GunnerInc 7 xor eax, eax Team Colleague

Uh, = is not equals it should be 2 equal signs == as in (ecx == 0) || (ecx == 2) etc...

The funny thing with macros (yes .if/.while are macros) is the error number will happen after the macro call...

datdude07 commented: great help! +1
GunnerInc 7 xor eax, eax Team Colleague

Exactly what the error description says - you cannot nest procedures.

Try this instead:
INCLUDE Irvine32.inc

.data
 
	ccolor DWORD 13
	bcolor DWORD 16
	SetColor PROTO,cc:DWORD,bc:DWORD
	prompt BYTE "Hi",0
 
.code
main PROC
 
	INVOKE SetColor,ccolor,bcolor
	mov edx,OFFSET prompt
	call WriteString
	
	exit
main ENDP

SetColor PROC,cc:DWORD,bc:DWORD
		mov eax,cc
		add eax,bc
		call SetTextColor
		ret
SetColor ENDP
END main
GunnerInc 7 xor eax, eax Team Colleague

Ah, the Assembler Newbie mantra: I Need, I want, Give me the code! :)

Auto-Completion is NOT an Assembler feature but an IDE feature, since you are using MASM, look for RadASM or WinASM both are good free IDE's for MASM

When you Assemble with MASM it WILL show you the line of the code error but NOT the error in your running program, for that you have to learn to use a debugger.

Since you state you have no interest in Assembly, just for your class, may I suggest you take a different class because you won't get anywhere.

GunnerInc 7 xor eax, eax Team Colleague

What assembler?

GunnerInc 7 xor eax, eax Team Colleague

Um, where do you want it displayed? On a billboard, command prompt, in the sky, DOS, in the dirt, windows? What OS does this display device use?

GunnerInc 7 xor eax, eax Team Colleague

Your Fibo algo works fine.

It prints wrong because you are passing the wrong thing to the write file function

mov edx,OFFSET pointarray

this is wrong, this is a pointer to a pointer. Remove offset and it will work. Better yet, cut down on uneeded globals and just do

mov edx,offset array

fix that and it will write the proper file. You cannot open it in notepad and get the correct results, you can open in a hex editor or what the homework says.

GunnerInc 7 xor eax, eax Team Colleague

Er, um, you are not writing what you want to write to the file!

;
; Writes a buffer to an output file.
; Receives: EAX = file handle, EDX = buffer offset,
; ECX = number of bytes to write
; Returns: EAX = number of bytes written to the file.

Line 44 eax, has the file handle from the return from CreateOutputFile BUT you are overwriting it with the contents of fileHandle which is 0. Change line 44 to:

mov    fileHandle, eax

Next, edx is supposed to be a pointer to the buffer to write to the file NOT the filename.

GunnerInc 7 xor eax, eax Team Colleague

That is because HLL instructions rarely convert to ONE mnemonic. It is only hard to read because you don't understand Assembly well.

GunnerInc 7 xor eax, eax Team Colleague

First off, you can only multiply 14 or 15 times then the result is too big for a word register

mov     ecx, 18
    mov     eax, 1
    
Mult:
    mov     edx, 2
    mul     edx
    push    eax
    push    ecx
    push    edx
    ; Print your hex numbers here
    pop     edx
    pop     ecx
    pop     eax
    dec     ecx
    jnz     Mult
GunnerInc 7 xor eax, eax Team Colleague

You downloaded "Flat Assembler"? That is FASM, your code is MASM. It WILL NOT assemble with FASM without some modifications.

GunnerInc 7 xor eax, eax Team Colleague

As I don't fully understand C, I am unsure where to print the message...

This would be my loop:

mov		cx, 3
Top:
	
	dec		cx
	jnz		Top

Next:

Right, you only want to loop 3 times. Don't use a memory variable for a loop counter, use cx, it was made for this... a "count" register

GunnerInc 7 xor eax, eax Team Colleague

How do you think it would work in assembly?

what mnemonic would you use to increment a variable/register?

what mnemonic would you use to test to see if it is within bounds?

what mnemonic would you use to jump back to the beginning?

Wait, you don't like putting in any effort.... just compile that in your c compiler and open the exe in olydbg to see how it is done...

GunnerInc 7 xor eax, eax Team Colleague

thanks thines.. but it is not running in 8086

What OS? If you are using Windows 7 the code WILL NOT work. Windows 7 does not run dos apps anymore. Might work by usind DOSBox or something similar

GunnerInc 7 xor eax, eax Team Colleague

Like I said in my post above, That is NOT complete code. It is missing code for scan_num

GunnerInc 7 xor eax, eax Team Colleague

I sure as hell won't help you "learn" how to do it, and I am sure there are many here that won't either. Please keep this crap out of DaniWeb

GunnerInc 7 xor eax, eax Team Colleague

If that is all the code you found,then it is incomplete.. Where is scan_num? It calls it, but it is not in the code posted

GunnerInc 7 xor eax, eax Team Colleague

What did your teacher teach you about that? What do you think the stack is for? What do you think registers are for? Once you can answer both of those questions and see the similarities and differences, you will be able to answer your own question.

Show some effort on your part, show some code that you think is relevant.. and when you are stuck come back and show us what you got and we will help.