flat assembler
Message board for the users of flat assembler.
Index
> Linux > "mov al, 1" vs "mov eax, 1" |
Author |
|
LocoDelAssembly 16 Oct 2008, 22:10
The handler could have something of the form "jmp dword [DISPATCH_TABLE+eax*4]", and to do that the handler must have checked EAX (or done "movzx eax, al" first), not AL. Even if it work on your computer better don't relay on expecting that the handler will only use AL and ignore the upper 24 bits of EAX, that could change in the future.
|
|||
16 Oct 2008, 22:10 |
|
Feryno 17 Oct 2008, 06:55
this does the same in 3 bytes but is a bit slowlier than 5-byte instruction mov eax,1 (but the worse performance may be ignored with the comparison of the Linux kernel code executed then...)
PUSH 1 POP EAX if you know that some register is certainly zeroed, e.g. ECX=0 then you can also use a smaller instruction LEA EAX,[ECX+1] This is a big buty of assembler code and human mind thinking about asm instructions - you can do the same thing in various and colorful ways! |
|||
17 Oct 2008, 06:55 |
|
Bror 17 Oct 2008, 14:38
Thanks for your answers, i'll use the whole eax then.
|
|||
17 Oct 2008, 14:38 |
|
LocoDelAssembly 17 Oct 2008, 14:47
Code: xor eax, eax ; 2 bytes inc eax ; 1 byte ; 3 bytes total |
|||
17 Oct 2008, 14:47 |
|
Bror 17 Oct 2008, 14:53
LocoDelAssembly, that is what I was using before the al vs eax thing. But I have another question, how do you output something to the terminal that's on the stack but of unknown size?
|
|||
17 Oct 2008, 14:53 |
|
Bror 18 Oct 2008, 09:16
I solved it myself with this little code:
Code: pop esi xor edx, edx count: inc edx lodsb or al, al jnz count sub esi, edx But how do I put a newline in the end of the data that esi points at? It doesn't work with stosb. |
|||
18 Oct 2008, 09:16 |
|
revolution 18 Oct 2008, 09:21
stosb uses edi. Try this:
Code: mov byte[esi],0x0a inc esi |
|||
18 Oct 2008, 09:21 |
|
Bror 18 Oct 2008, 09:42
With a little tweaking I managed to get that working, thanks!
|
|||
18 Oct 2008, 09:42 |
|
bitRAKE 18 Oct 2008, 14:52
Code: pop edi or ecx,-1 mov al,0 repne scasb inc ecx lea edi,[edi+ecx] not ecx mov byte [edi+ecx],10 |
|||
18 Oct 2008, 14:52 |
|
Bror 19 Oct 2008, 14:51
I'm sorry but I don't understand the "repne scasb" part. Could you explain it?
|
|||
19 Oct 2008, 14:51 |
|
bitRAKE 19 Oct 2008, 16:47
SCASB compares the byte at [EDI] with AL - storing the result in the flags. REPNE deincrements ECX and repeats the instruction while the Z flag is clear and ECX is not zero. Since (2^32-1) has been stored in ECX it is impossible for ECX to be zero before AL is found in the string. The resulting value in ECX is the negative of (the string length plus one).
|
|||
19 Oct 2008, 16:47 |
|
LocoDelAssembly 19 Oct 2008, 17:54
Another possible way:
Code: pop edi push edi or ecx, -1 mov al, 0 repne scasb mov byte [edi-1], 10 pop edi (At the end the registers have the same values as bitRAKE's code) |
|||
19 Oct 2008, 17:54 |
|
bitRAKE 19 Oct 2008, 22:11
LocoDelAssembly wrote:
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
19 Oct 2008, 22:11 |
|
LocoDelAssembly 19 Oct 2008, 23:37
Damn, I forgot about ECX. Yes, correcting the code also makes the code smaller but only by one byte (using add also makes the code one byte smaller).
|
|||
19 Oct 2008, 23:37 |
|
Bror 22 Oct 2008, 21:24
Ok, more trouble. How do I get the terminal size (lines and columns) from terminfo in assembly? Sorry that I bomb my own tread but I'm to slack to create a new one.
|
|||
22 Oct 2008, 21:24 |
|
Endre 24 Oct 2008, 18:33
Here the code. Note that ws_xpixel and ws_ypixel aren't always set. For instance on gnome terminal you will get 0 for these values, on xterm however the correct pixel values are stored. Nevertheless ws_row and ws_column are fortunately always available.
Code: format ELF executable entry start SYSCALL_EXIT equ 1 SYSCALL_IOCTL equ 54 STDOUT equ 1 IOCTL_TIOCGWINSZ equ 0x5413 ;;; winsize structure see include/asm-i386/termios.h struc winsize { .ws_row dw ? .ws_col dw ? .ws_xpixel dw ? .ws_ypixel dw ? } segment readable executable start: ;; iotcl(stdout, TIOCGWINSZ, &terminal_size) mov eax, SYSCALL_IOCTL mov ebx, STDOUT mov ecx, IOCTL_TIOCGWINSZ mov edx, terminal_size int 0x80 ;; set exit value mov ebx, eax mov eax, SYSCALL_EXIT int 0x80 segment readable writeable ;;; winsize structure instance terminal_size winsize |
|||
24 Oct 2008, 18:33 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.