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

[GAS,8086] How to print values of registers?

Name: Anonymous 2009-11-03 6:56

Does anyone know how to do this?

.text
.globl main

main:
 movl $0x1,%eax
 movl $0x2,%ebx
 movl $0x3,%ecx
 movl $0x4,%edx
 # print eax
 # print ebx
 # print ecx
 # print edx
 ret


THANKS!

Name: Anonymous 2009-11-03 7:05

.FORMAT:
    .string    "%d\n"
   
main:
    ...
   
    movl    $.FORMAT, %edx
    movl    %eax, 4(%esp)
    movl    %edx, (%esp)
    call    printf

Name: Anonymous 2009-11-03 7:06

Read SICP

Name: Anonymous 2009-11-03 7:10

>>1
Uh, uncomment the prints?

Name: op 2009-11-03 7:12

>>2

OP here.
Thanks for the input.
Where can I learn more about what you wrote (.FORMAT,etc)?

Thanks again!

Name: op 2009-11-03 7:22

>>4
OP here, it shouldn't work that way. ;)

We're using an object to link with our program to print the values.

So my code is actually:


.text
.globl main
main:
      movl $0x1, %eax
      movl $0x2, %ebx
      movl $0x3, %ecx
      movl $0x4, %edx
      call imprime_eax
      call imprime_ebx
      call imprime_ecx
      call imprime_edx
      ret


Teacher said to compile like this:
gcc -g file.s imprime.o -o file

But I'm an asshole, and love to compile with lots of shit, shit being warning and error flags:
gcc -x assembler -g -pass-exit-codes -pedantic -Wall -Wextra -time file.s imprime.o -o file

By doing this the compiler bursts into flags with errors and warnings.

So I wanted to know if I could use a routine to print the values of the registers, without using the teacher's file.

Name: Anonymous 2009-11-03 8:10

Just call printf?

Name: Anonymous 2009-11-03 8:20

gcc -x assembler -g -pAs-sexit-codes -pedo -Wall -Wextra -time file.s imprime.o -o file

Name: Anonymous 2009-11-03 11:59

I don't think you'll ever succeed. Enjoy dropping out.

Name: Anonymous 2009-11-03 13:51

AT&T syntax is fucking horrible.

Name: Anonymous 2009-11-04 7:24

>>2

Doesn't work.

Name: Anonymous 2009-11-04 8:19

How to get gcc (MinGW port) to build my fuckin program without adding 12+ kb of horse-shit to the binary???

Name: Anonymous 2009-11-04 8:41

>>12
It isn't horseshit, it's a lot of static linking from mscvrt on Windows. On *nixes it produces particularly compact programs.

Name: Anonymous 2009-11-04 9:27

>>13
Manually assembling with gas and linking still produces binaries half the size of what gcc spits out.

Name: Anonymous 2009-11-04 10:25

>>13
Then gcc fails. MSVCRT should be linked dynamically.

Name: Anonymous 2009-11-04 10:29

>>14
Manually assemble my anus.

Name: Anonymous 2009-11-04 10:47

Name: Anonymous 2009-11-04 11:05

>>13
gcc tends to produce many redundant data on windows executables.
I can easily make 1-3kb executables on Windows using MSVC, this is done by disabling debug information, dynamically linking MSVCRT(or similar), and linking with a fairly low file alignment (lowest safest portable value possible was about 0x400). This results in a small and clean PE header, a .text section containing just the necesarry code, an .rdata section if any static immutable constants are present (usually contains at least the Import Address Table, and the Import Table), and a .data section for defined and undefined non-const data. This makes puts it at about ~3KB, for a minimal functional executable. It can be made much tinier by abusing the PE format, but one shouldn't expect the compiler to do that for you: you either write your own tools for this, or create the file manually or will have to play more tricks with your linker.

I do believe gcc is capable of doing such things, but I haven't tried it myself. Sadly, most gcc compiled exes in win32 I've seen were somewhat bloated, but that doesn't convience me that it's not doable, as a good deal of win32 executables compiled using msvc are fat as well because people don't know or care enough to make them tiny.

If size is of such great importance, one of the many tiny PE packers can be used to reduce the size by quite a bit, there's some packers which generate under 1KB executables with ease (as long as the code/data is that compressible/tiny).

Name: Anonymous 2009-11-04 11:09

Hey! Who cares about building on Windows, it's a shitty platform.

Name: Anonymous 2009-11-04 11:09

Oh, and you can also remove the standard entrypoint, to replace it with your own, this would pretty much remove any library code from your file, if you're linking against msvcrt, however it should be noted that you will not have access to the parameters you get to main or WinMain, if you change the entrypoint (the standard entrypoint parses the command line arguments and calculates the other parameters, then calls main or WinMain with them - if you do need to do that, you'll have to parse them yourself, in which case, it might be just fine to use the default entrypoint anyway).

Name: Anonymous 2009-11-04 11:13

>>19
There are 6 types of people that run Windows: DEVELOPERS, DEVELOPERS, DEVELOPERS, DEVELOPERS, DEVELOPERS, and DEVELOPERS.

Name: Anonymous 2009-11-04 11:47

>>21
YHBT, I just thought your anus would really like to know what happened.

Name: Anonymous 2009-11-04 11:53

>>22
>>19 here, I also posted >>21 and YHBT

Name: Anonymous 2009-11-04 13:23

>>23
Trolling by pretending to be trolled - that's unusual.

Name: Anonymous 2009-11-04 14:12

>>24
It isn't.

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