1

I am a little confused about why Assembly Languages have syscalls. Here are some questions:

  1. Isn't Assembly Language the lowest level language (before machine code)? Why does it have to make a "syscall" to the Linux Kernel's C Code?

For example, to print to screen, we need to do a "syscall" (using MIPS): enter image description here

  1. Does the Linux Kernel's "syscall" C code eventually also become Assembly Language?

  2. How do I print to the terminal using MIPS without using a syscall? Am just curious how the actual Assembly Language looks like, examples using other Assembly Languages besides MIPS would also be really helpful.

My guess is that the C programs I have converted to Assembly Language are still user-space programs that still need to use syscalls to execute kernel-space instructions?

Ryn
  • 441
  • 2
  • 10
  • That's not a Linux system call (which would need a file descriptor and a length for a `write` system call, as well as a pointer). That's one of the toy system calls from the system that MARS/SPIM simulate (https://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.html), this being print string which takes a pointer to a zero-terminated string so it can't output arbitrary binary data. – Peter Cordes Apr 23 '22 at 09:05
  • A "terminal" itself is something that only exists thanks to the OS. If you mean write to video memory, look at MARS's bitmap graphics option where the simulated guest machine has access to a region of memory that's treated as video RAM. (The simulator updates the window when you store into it.) For real CPUs, on bare metal yes you just store bytes into video RAM. In VGA text mode, you can store actual ASCII characters, otherwise you need to copy font glyphs / draw the pixels of each character. – Peter Cordes Apr 23 '22 at 09:10
  • Related: [Does ARM have any mechanism like the VESA/VGA text mode console on x86?](https://stackoverflow.com/q/29762307) . Also [Does modern PC video hardware support VGA text mode in HW, or does the BIOS emulate it (with System Management Mode)?](//stackoverflow.com/q/61521819) re: the fact that modern x86 PCs do still have hardware that supports VGA text mode. For some details about actually using it, see https://wiki.osdev.org/Printing_To_Screen with a C example using `volatile char *video = (volatile char*)0xB8000;` and [Graphics mode in assembly 8086](//stackoverflow.com/q/48648548) – Peter Cordes Apr 23 '22 at 09:14
  • [Displaying text video memory at 0xb8000 without using the C library](https://stackoverflow.com/q/37354717) looks like what you're looking for on x86. (x86 is interesting for this because the IBM PC is kind of a hardware compatibility standard that most modern machines can pretend to be compatible with, booting into legacy mode. "compat support modules" in a UEFI BIOS. So regardless of what actual video card or iGPU you have, you can boot in 16-bit mode and run instructions that store to a specific physical address, to put ASCII characters in video memory and thus on screen.) – Peter Cordes Apr 23 '22 at 09:20
  • See also comments on [Writing directly to the screen from an x86\_64 Linux machine](https://stackoverflow.com/q/62218528) re: why OSes need to stop user-space programs from doing that. – Peter Cordes Apr 23 '22 at 09:21

0 Answers0