Assembly with %include at the top – Printing Outputs Unexpected Result: just an ” S”

You included stuff at the top of your bootloader, where it will executes first. Instead include extra functions where they aren’t in the main path of execution and are only reached by call. This should work, placing the %include directives where it’s safe to put extra function or data, just like if you were writing … Read more

NASM Error Parsing, Instruction Expected

That assembly language is MASM, not NASM. For starters, NASM segments are defined differently. Instead of Code segment word public ‘CODE’ we write .section text And that “ASSUME” declaration… You must have an ancient book. That is old, old MASM code. Brings back memories from the early 1980s for me! There are many differences between … Read more

Number of executed Instructions different for Hello World program Nasm Assembly and C

The number of instructions executed in program 1) is high because of linking the program with system library’s at runtime? Yep, dynamic linking plus CRT (C runtime) startup files. used -static and which reduces the count by a factor of 1/10. So that just left the CRT start files, which do stuff before calling main, … Read more

Shadow space example

The shadow space must be provided directly previous to the call. Imagine the shadow space as a relic from the old stdcall/cdecl convention: For WriteFile you needed five pushes. The shadow space stands for the last four pushes (the first four arguments). Now you need four registers, the shadow space (just the space, contents don’t … Read more

What are the sizes of tword, oword and yword operands?

Looking at the nasm source, it looks like: ‘oword””DO’ is 8 times as big as “word” (O for “octoword”), synonymous with dqword (“double-quad”); that would be 128 bits, corresponding to the size of an SSE vector register. ‘tword””DT’ is 80 bits (T for “ten bytes”), the full size of an Intel x87 floating point register. … Read more

Assembly difference between [var], and var

In x86 Intel syntax [expression] means content of memory at address expression. (Except in MASM when expression is a numeric literal or equ constant with no registers, then it’s still an immediate) expression without brackets depends on Assembler you are using. NASM-style (NASM, YASM): mov eax,variable ; moves address of variable into eax lea eax,[variable] … Read more

How do i read single character input from keyboard using nasm (assembly) under ubuntu?

It can be done from assembly, but it isn’t easy. You can’t use int 21h, that’s a DOS system call and it isn’t available under Linux. To get characters from the terminal under UNIX-like operating systems (such as Linux), you read from STDIN (file number 0). Normally, the read system call will block until the … Read more

How to force NASM to encode [1 + rax*2] as disp32 + index*2 instead of disp8 + base + index?

NOSPLIT: Similarly, NASM will split [eax*2] into [eax+eax] because that allows the offset field to be absent and space to be saved; in fact, it will also split [eax*2+offset] into [eax+eax+offset]. You can combat this behaviour by the use of the NOSPLIT keyword: [nosplit eax*2] will force [eax*2+0] to be generated literally. [nosplit eax*1] also … Read more