Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 11th, 2006, 07:37 PM
WraithM WraithM is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 1 WraithM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 33 sec
Reputation Power: 0
X86 Assembly problem

I've been teaching myself x86 Assembly and machine code. I ran into some trouble.

Note: This is all under FreeBSD using the NASM assembler. FreeBSD pushes kernel call arguments onto the stack rather than in Linux where the arguments are moved into registers.

Here's my Macro code for NASM
Code:
%define stdin 0
%define stdout 1
%define stderr 2

%define SYS_nosys 0
%define SYS_exit 1
%define SYS_fork 2
%define SYS_read 3
%define SYS_write 4

section .text
align 4

access.the.bsd.kernel:
        int 80h
        ret

%macro system 1
        mov eax, %1
        call access.the.bsd.kernel
%endmacro

%macro sys.exit 0
        system SYS_exit
%endmacro

%macro sys.fork 0
        system SYS_fork
%endmacro

%macro sys.read 0
        system SYS_read
%endmacro

%macro sys.write 0
        system SYS_write
%endmacro


Here's the code for my program.
Code:
%include 'system.inc'

section .data
    msg db "above",0Ah
    len equ msg
    
    msg2 db "below",0Ah
    len2 equ msg2
    
    msg3 db "done",0Ah
    len3 equ msg3

section .text
global _start

_start:
    mov eax, 5 
    cmp eax, 3
    jl .ifbelow

    push dword len
    push dword msg
    push dword stdout
    sys.write
    jmp .done

.ifbelow:
    push dword len2
    push dword msg2
    push dword stdout
    sys.write
    
.done:
    push dword len3
    push dword msg3
    push dword stdout
    sys.write
    
    push dword 0
    sys.exit


Now the problem is that when I call the kernel to print out msg it takes the whole .data section with it. It displays msg, msg2, and msg3.

Like so:
matt@mdwuni2:~/programming/Assembly/cmp# ./cond
above
below
done
done

The reason it prints out done twice is that the unconditional jump is working and sends it to the end of the program where I print out done again.

When I try to change the comparison to: cmp eax, 7
Where the program goes on the conditional jump to .ifbelow and prints out below.

Like so:
matt@mdwuni2:~/programming/Assembly/cmp# ./cond
below
done
done

The kernel call is dragging msg2 and msg3 and displaying it.

I've tried rearranging the .data section and it all seems to be having the same problem.

Am I doing something completely wrong?
All the jumps are working properly, it's just the displaying of the .data section that's messing up.

If anybody can help me I'd be extremely thankful

Thanks!
-WraithM

EDIT: Also if anybody can tell me a way to display the values of registers that'd be really awesome! That's something that I haven't figured out.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > X86 Assembly problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT