LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-18-2004, 12:31 AM   #1
KneeLess
Member
 
Registered: May 2003
Distribution: Debian GNU/Linux 3.0 Sid, OpenBSD 3.5
Posts: 190

Rep: Reputation: 30
NASM, Jumping, and I'm new to this...


Hello. If anyone here knows assembly I'd sure like you to help me out. Here is my file:

Code:
section .text                                 ;linker things, right?
        global _start


msg db   "Hello! It works!\n",0xa       ;my test things
len equ  $ - msg

_start:
        mov   edx,45                               ;move 45 into edx, and 46 into ecx
        mov   ecx,46
        test  edx,ecx                               ;test and jump to testFunc if edx is
        jle   testFunc                               ;less than ecx, which it is, if not, jump
        jmp   endThis                              ;to the end

testFunc:
        mov  edx,len                               ;Normal HelloWorld diddlies..
        mov  ecx,msg
        mov  ebx,1
        mov  eax,4
        int  0x80
        jmp  endThis                               ;Finish

endThis:
        mov  eax,1
        int  0x80
The logic is pretty easy to follow. The tutorial I was following used eax and ebx as registers for the test numbers, but I don't like useing those as..."variables". I know they're not variables, but they're for syscall things. I was uncomfortable. The problem is that when I run the program, output isn't printed to stdout. Also: are registers all letters? Like ecx, edx, eex, efx...etc.

Thanks

Last edited by KneeLess; 02-18-2004 at 12:38 AM.
 
Old 02-18-2004, 01:24 AM   #2
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
First, You have TEST and CMP confused. TEST is used to check for the existance of certain bits in an operand, then sets FLAGS. CMP subtracts the two operands and sets FLAGS. For what you want to do, replace TEST with CMP and the example will work.

Second, { msg db "Hello! It works!\n",0xa } this would be correct had you been using a C
function like printf to output msg. But since you are using the write syscall, your \n will not be
interpreted and a \n will be outputted as well. For a newline you will have to use 0xA, the ASCII LineFeed character, for a newline (which was at the end of msg).

Third, the general purpose registers are:

32-bit:
eax
ebx
ecx
edx
esi
edi
ebp
esp
eflags, eip (not for general use)

16-bit:
ax
bx
cx
dx
si
di
bp
sp

16-bit segment registers:

CS, SS, DS, ES, FS, GS

8-bit(high):
ah
bh
ch
dh

8-bit(low):
al
bl
cl
dl

Hope I helped...
 
Old 02-18-2004, 01:46 AM   #3
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
using '\n' with write is fine
 
Old 02-18-2004, 02:29 AM   #4
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
Quote:
Originally posted by infamous41md
using '\n' with write is fine
You need to read my post again,
I said that you cannot use \n with the
write SYSCALL. I also said \n would be
ok had KneeLess been using C to output
msg, but he is not. The C function write
can accept \n, but sycall #4 (write) does
not accept escape sequences.
 
Old 02-18-2004, 03:18 AM   #5
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
Incase you need proof, try running this code...
Code:
;	no_newline.s

segment .data
msg     db      "I do NOT have a newline.\n"
len     db      $-msg

segment .text

global  _start
_start:

mov     edx,len
mov     ecx,msg
mov     ebx,1
mov     eax,4
int     0x80

mov     eax,1
int     0x80
compile using:
Code:
~> nasm -f elf no_newline.s
~> ld no_newline.o -o no_newline

Last edited by jinksys; 02-18-2004 at 03:19 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Jumping mouse jumico Linux - Newbie 3 04-24-2005 03:15 PM
monitor jumping around? powerlifter450 SUSE / openSUSE 2 02-24-2005 07:24 PM
Nasm essoft478 Linux - Software 2 09-13-2004 05:33 PM
DVD JUmping Boffy Linux - Hardware 3 03-31-2004 07:21 AM
Jumping in Head first dvlmn666 Linux - Newbie 4 12-18-2003 02:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration