Up vote 1 down vote favorite share g+ share fb share tw.
I am trying to print a single digit integer in nasm assembly on linux. What I currently have compiles fine, but nothing is being written to the screen. Can anyone explain to me what I am doing wrong here?
Section . Text global _start _start: mov ecx, 1 ; stores 1 in rcx add edx, ecx ; stores ecx in edx add edx, 30h ; gets the ascii value in edx mov ecx, edx ; ascii value is now in ecx jmp write ; jumps to write write: mov eax, ecx ; moves ecx to eax for writing mov eax, 4 ; sys call for write mov ebx, 1 ; stdout int 80h ; call kernel mov eax,1 ; system exit mov ebx,0 ; exit 0 int 80h ; call the kernel again linux assembly nasm link|improve this question asked Aug 1 '11 at 19:34FrozenWasteland925 100% accept rate.
You are assigning eax to ecx, and then 4. It's probably there. – Josh Aug 1 '11 at 19:38.
This is adding, not storing: add edx, ecx ; stores ecx in edx This copies ecx to eax and then overwrites it with 4: mov eax, ecx ; moves ecx to eax for writing mov eax, 4 ; sys call for write EDIT: For a 'write' system call: eax = 4 ebx = file descriptor (1 = screen) ecx = address of string edx = length of string.
I tried this, and it also compiles fine, but nothing is being written to the screen. – FrozenWasteland Aug 1 '11 at 19:59 I still can't get it working, but I will make this the accepted answer. – FrozenWasteland Aug 1 '11 at 20:36 @FrozenWasteland - The remaining problem is mentioned in this answer, but without calling your attention specifically to it: "ecx = address of string edx = length of string" but you have been trying to provide the data byte itself inc ecx rather than the address there and a length in edx.
– Chris Stratton Aug 2 '11 at 16:12.
From man 2 write ssize_t write(int fd, const void *buf, size_t count); In addition to the other errors that have been pointed out, write() takes a pointer to the data and a length, not an actual byte itself in a register as you are trying to provide. So you will have to store your data from a register to memory and use that address (or it it's constant as it currently is, don't load the data into a register but load its address instead). Here's an example: http://www.cin.ufpe.
Br/~if817/arquivos/asmtut/index. Html#helloworld.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.