Author Topic: [NASM]can't print output  (Read 1355 times)

0 Members and 1 Guest are viewing this topic.

Offline $Clone

  • Peasant
  • *
  • Posts: 86
  • Cookies: 5
  • $---Shadowalker---$
    • View Profile
[NASM]can't print output
« on: March 19, 2015, 11:21:47 am »
hi.....am new to asm so i wanted to do a simple 1+2=3 and get the output three but it seems i can't get what i want  :( .....there are no syntax error but maybe register but i can't seem to pin point the place.

Code: (Assembly) [Select]
section .text
global _start
_start:
mov eax,1
add eax,2
mov ebx,1
mov eax,4
int 0x80
mov eax,1
int 0x80


so i thought maybe save the result so:
Code: (assembly) [Select]
section .text
global _start
_start:
mov eax,1
add eax,2
mov [result],eax
mov ebx,1
mov eax,4
mov ecx,result
mov ebx,1
int 0x80
mov eax,1
int 0x80
section .bss
result resb 1


help  :-\ ....

Offline HTH

  • Official EZ Slut
  • Administrator
  • Knight
  • *
  • Posts: 395
  • Cookies: 158
  • EZ Titan
    • View Profile
Re: [NASM]can't print output
« Reply #1 on: March 19, 2015, 12:46:03 pm »
Code: [Select]
section .bss
    datVariable    resb    4       

section .text
    global _start

_start:
    mov  eax, 1 ;wuts this a number?
    mov  ebx, 2 ; wut, another one?
    add  eax,ebx ; shit's getting cray
    add  eax, 30h ;here be black magic
    mov  [datVariable], eax ;black magic also here

    mov  eax, 4 ;dat syscall
    mov  ebx, 1 ;dat fd
    mov  ecx, datVariable ;The lack of [] is important yo
    mov  edx, 1 ;dat length tho
    int  0x80 ;you got this from here?

    mov eax, 1 ;coo
    mov ebx, 0  ;i'd really hate to explain it
    int 0x80 ;bye bye for now

orrr if you wanna use  the stack directly instead of the bss section..
Code: [Select]
section .text
    global _start

_start:
    mov  eax, 1 ;wuts this a number?
    mov  ebx, 2 ; wut, another one?
    add  eax,ebx ; shit's getting cray
    add  eax, 30h ;here be black magic
    push eax ;different type of black magic

    mov  eax, 4 ;dat syscall
    mov  ebx, 1 ;dat fd
    mov  ecx, esp ;wut is dis? A potential problem? of course it is.
    mov  edx, 1 ;dat length tho
    int  0x80 ;you got this from here?

    mov eax, 1 ;coo
    mov ebx, 0  ;i'd really hate to explain it
    int 0x80 ;bye bye for now
tl;dr you weren't dealing with an ascii value and you were trying to print the address of 3, not an address where 3 was.
« Last Edit: March 19, 2015, 12:55:36 pm by HTH »
<ande> HTH is love, HTH is life
<TurboBorland> hth is the only person on this server I can say would successfully spitefuck peoples women