Re:A fundamental introduction to x86 assembly programming
by d0mine on Friday May 20, 2016 @08:58PM
(#11742639)
Unrelated: the code is equivalent to read(fd, buf, RECORD_SIZE) that may read less than RECORD_SIZE.
The function should read in a loop, to fulfill its contract (read a record).
#include <unistd.h>
ssize_t read_record(int fd, void* buf, size_t record_size, size_t* written) {
for (*written = 0; *written < record_size; ) {
ssize_t n = read(fd, (char*)buf + *written, record_size - *written);
if (n < 1)
return n; /* error or EOF */
*written += n;
}
return *written;
}
For a quick idea of what ASM can look like if you build up the foundations step-by-step, and understand what you're working with:
With the definitions in place, its like a whole different language.For reference, the definitions are simply a text file with contents similar to:
Or (record-defs.s in the example) clearly describing the data with: This book opened my eyes to the concrete, data driven nature of the problems I'm trying to solve, at an atomic level. It somehow dispelled all the magic behind programming, while exciting the mechanical side of my brain, leaving me with that "its just a machine, I can solve any problem if I just trace things patiently until I understand the parts and how they interact".