Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Assembly

Name: Anonymous 2011-04-25 15:40

Hey /prog/, I am learning Pentium Assembly on linux, using nasm assembler. I've been having trouble with the stack operations. Could somebody explain how I can simply push 4 integers(hex/dec) onto the stack, and then later pop them off? I get some really weird messages when I try to do this.

Thanks a lot.

Name: Anonymous 2011-04-25 15:59


PUSH 5
PUSH -12
PUSH 0x1234
PUSH EAX
PUSH DWORD [ESI]


What's so complicated about that?

Name: Anonymous 2011-04-25 16:05

>>2

u mena


push 5
push -12
push 0x1234
push eax
push dword [esi]

Name: Anonymous 2011-04-25 16:13

>>1
Read the Intel manuals.

Name: Anonymous 2011-04-25 16:22

>>2-4 What the hell are you talking about? What part of getting really weird messages when trying to do this do you not understand?

Name: Anonymous 2011-04-25 16:29

>>5
OP has provided no example messages

Name: Anonymous 2011-04-25 16:37

>>5
What part of read the Intel manuals because giving no code at all nor any of those weird error messages make you look like a retarded newbie just like that noko in the sage field do you not understand?

Name: Anonymous 2011-04-25 16:44

; following code will output "Lisp sucks"

mov rdx, mypenis
mov rcx, 9001
call setSize

call doesLispSuck
test rax, rax
jnz lisp_sucks
mov rdx, NOT_SUX_TEXT
call puts
ret
lisp_sux:
mov rdx, SUX_TEXT
call puts
ret

Name: Anonymous 2011-04-25 16:45

>>8
following code
I don't see any code, code goes in [code] tags!

Name: Anonymous 2011-04-25 17:44

>>8
You suck at asm and have obviously not read your SICP to be hating on Lisp.
Here's how to write it:

.code
start:
call DoYouFail
push dword ptr [eax+pFailures]
call puts ; using fast printf is left to the user (see: http://dis.4chan.org/read/prog/1279520490/3 )
ret

; valid return value: 0 or 1
DoYouFail:
xor eax,eax
inc eax
ret

.data
szFail db 'FAIL',0
szRule db 'RULE',0

pFailures dd offset szRule
          dd offset szFail

Name: >>10 2011-04-25 17:45

make that eax*4

Name: >>10 2011-04-25 17:49

Another possibility:

.code
start:
mov edx, offset szRule
mov esi, offset szFail
call DoYouFail
cmovnz edx, esi
push edx
call puts
ret

DoYouFail:
xor eax,eax
inc eax
ret

.data
szFail db 'FAIL',0
szRule db 'RULE',0

Name: Anonymous 2011-04-25 18:12

>>12
That should be _start, and you can't just ret from it.


section .code
_start: mov edx, hnHungarianNotationConsideredHarmful
        mov esi, hnHungarianNotationConsideredBeneficial
        call failp
        cmovz edx, esi
        push edx
        call puts
        syscall1 1,0 ; macro left as an exercise for the reader

failp:  xor eax, eax
        inc eax
        ret

section .data
hnHungarianNotationConsideredHarmful: db 'FAIL',0
hnHungarianNotationConsideredBeneficial: db 'FAIL ANYWAY',0

Name: Anonymous 2011-04-25 18:21

Setting a register to zero by xoring it with itself has been slower since probably the Pentium Pro. Similarly, swapping the values of two registers is faster using an additional temporary register, even if you have to save its value on the stack.

Name: Anonymous 2011-04-25 18:39

>>14
Real men define their own zero macro.

Name: OP 2011-04-25 18:59

Hmm, I ended up figuring it out, thanks guys. Right now I'm trying to use the stack to convert from hex to decimal. Let's say I have the hex value: 2B3A. I first take each character, starting from the left, and push it on the stack. So if I had 2B3A, I would end up with this:

ESP -> 10
3
11
2

I'm trying to figure a good way to convert this to decimal

Name: Anonymous 2011-04-25 19:15

Name: Anonymous 2011-04-25 20:29

>>16
What are you using for output, ``faggot''?

Name: Anonymous 2011-04-25 20:54

>>16

So where do you get the string from?

Why push it onto the stack at all?

Name: Anonymous 2011-04-26 8:03

Name: Anonymous 2011-04-26 8:04

Name: Anonymous 2011-04-26 8:13

Name: Anonymous 2011-04-26 8:18

Name: Anonymous 2011-04-26 8:23

Name: Anonymous 2011-04-26 8:28

Name: Anonymous 2011-04-26 8:34

Name: Anonymous 2011-04-26 8:39

Name: Anonymous 2011-04-26 8:44

Name: Anonymous 2011-04-26 8:49

Name: Anonymous 2011-04-26 8:55

Name: Anonymous 2011-04-26 9:00

Name: Anonymous 2011-04-26 9:05

Name: Anonymous 2011-04-26 9:11

Name: Anonymous 2011-04-26 9:16

Name: Anonymous 2011-04-26 9:21

Name: Anonymous 2011-04-26 9:26

Name: Anonymous 2011-04-26 9:32

Name: Anonymous 2011-04-26 9:37

Name: Anonymous 2011-04-26 9:42

Name: Anonymous 2011-04-26 9:47


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List