Hi!
I'm a total asm newbie. I'm using NASM on GNU/Linux. I'm trying to push 3 characters into stack and then print them, it does print 3 characters, but not the right ones.
strace output:
Here's the write system call:
ssize_t write(int fd, const void *buf, size_t count);
I'm not sure why it doesn't print ABC. It last argument in strace output '3A' looks strage also, it should be just 3 I guess. Thank you!
I'm a total asm newbie. I'm using NASM on GNU/Linux. I'm trying to push 3 characters into stack and then print them, it does print 3 characters, but not the right ones.
strace output:
strace ./write
..
write(1, "A\0\0", 3A) = 3
..
section .data
section .text
global _start
_start:
push 'C'
push 'B'
push 'A'
mov eax,4
mov ebx,1
mov ecx,esp
mov edx,3
int 80h
mov eax,1
mov ebx,0
int 80h
Here's the write system call:
ssize_t write(int fd, const void *buf, size_t count);
I'm not sure why it doesn't print ABC. It last argument in strace output '3A' looks strage also, it should be just 3 I guess. Thank you!
push 'A' is in fact push dword 0x00000040
you should do push 'ABC', this is push dword 0x00424140
you should do push 'ABC', this is push dword 0x00424140
By looking at the head of the "Write" procedure, you would be able to say that the second parameter is the pointer to the beginning of the characters not the characters themselves. Therefore, you should put those characters in adjacent places in the same segment and pass the pointer to the one with the memory location less than the others as the second parameter to the "write" routine.
Here is an example of a procedure which fills the value of the AL, AH and the DL registers with the correct parameters.
Here is an example of a procedure which fills the value of the AL, AH and the DL registers with the correct parameters.
GetParams PROC NEAR
PUSH ES ; Push the extra segment onto the stack
PUSH BP ; Push the base pointer onto the stack
MOV BP , SP ; Move the stack pointer to the base pointer
MOV BX , WORD PTR ; BX now points to the first parameter's offset
MOV ES , WORD PTR ; ES now points to the segment parameter
MOV AL , BYTE PTR ES: ; AL is the first byte inside the parameter
MOV AL , BYTE PTR ES: ; AH is the second byte inside the parameter
MOV AL , BYTE PTR ES: ; DL is the third byte inside the parameter
POP BP ; Restore the base pointer
POP ES ; Restore the extra segment
RET 0004h ; Return and remove 2 WORDs from the stack
GetParams ENDP
Good luck.mov bp,B800
mov es,bp
mov di,722
push "A"
push "B"
push "C"
pop ax
mov ah,0F
stosw
pop ax
mov ah,0F
stosw
pop ax
mov ah,0F
stosw
mov es,bp
mov di,722
push "A"
push "B"
push "C"
pop ax
mov ah,0F
stosw
pop ax
mov ah,0F
stosw
pop ax
mov ah,0F
stosw