assembly - What Linux does when I make write system call? -


I'm a newbie for Linux, for assembly programming (GAS) and English. So, sorry if I write something wrong. I hope Google Translate will help me not write all this bad.

I want to know how to write a set of numbers, in the section .data , any libraries (like printf) ) without a function called text file and such assembler-only prospects. I do not want a ready-made solution. I want to know what the Linux kernel does in writing. how it works? How was it designed?

I am trying to print the list of numbers STDOUT, but I get a strange mark in my terminal. I thought this happens because I do not understand how to work with call system call is right.

What this is for me now

  .section Data list:. Long time 12, 31, 42 .section .text .globl _start _start: $ 4,% eax movl $ 1,% EBX movl $ list, movl% ECX movl $ 12,% EDX integer $ 0x80 movl $ 1,% eax Movl $ 0,% EBX integer $ 0x80  

This code works for .ascii "World Hello \ 0" , but not a list of numbers is.

First of all: (eg from libc.so).

Even library functions use internal system calls

A system call is a special type of call instruction more or less. This instruction will call some code (such as a call), but it will keep the CPU in privileged mode (can access the CPU address in this mode which will not be able to enter user mode) and at the address where the function is called Will be fixed (defined by a special register which can only be accessed in the privileged mode).

Evaluates the function that is called the EAX Register (assuming 32-bit Linux for x86) and is performing the desired action (if EX is 4 then a "written" is done ).

The code beyond the system call is very, very large and complex, eventually a system call will result in writing data to I / O ports and memory areas, for example related to a disk drive or graphics card.

For example, write characters on the screen to be located on the graphics memory which trivial addresses 0xB8000 which matches the map address 0xC00B8000 in the old kernel.

This means a "mov" instruction will be the result of being written in a character to know some data such as when the screen is in text mode then it is displayed on the screen.

However this address (0xC00B8000) can be accessed only when the CPU is in privileged mode, otherwise an exception (this is also some kind of "call" which is due to hardware and not by software) Is thrown; In this case it is said that something like "just error" will be printed regularly and will stop the program.

--- Edit ---

About your edited question:

"write" system call screen or ASCII character to a file Will write.

If you want to write numbers then you must change the number for a sequence of ASCII characters.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -