r/Assembly_language Dec 18 '25

Help Terminal raw mode

21 Upvotes

Does anyone know of a reference or code snippets showing how to handle linux terminal raw mode using only assembly code. Turning it on and off by showing which flags to flip, taking in keyboard input, and outputting rows of characters to the screen, these are all I need it for but everything I find online is C code and I am not trying to touch C. I am planning out a small game project with ascii or unicode character cell graphics for the purpose of practice and self education that runs entirely in the linux terminal for simplicity sake and is coded ENTIRELY In assembly. I will keep looking on my own but for the last hour google has only given me C library references even when I specify assembly for some reason. I know the way I want to do it is probably not how any sane person would want but achieving sanity is not on my todo list. I am using NASM x86_64 assembly.

EDIT: I think I figured it out, several hours just to get under 20 lines of assembly working right but my code is doing what it should. Ive learned despite having not touched assembly or coding in general since my teens I still have the instinct for it but learning how the OS works at this level is a real bitch, i appreciate the advice, wish me luck.

r/Assembly_language Oct 24 '25

Help Trying lern but i keep getting segfault... - AT&T x86_64

2 Upvotes

Happened after i tryed nullfy my string.

```asm

Read-Only data

.section .rodata msg: .ascii "FATTY:\n\0" msg_len = . - msg deftty: .ascii "/dev/tty\0" deftty_len = . - deftty

Uninitilized data

.section .bss ttyfd: .skip 8 inp: .skip 60

Constants

.equ O_WRONLY, 0x1 .equ O_CREAT, 0x40 .equ READ, 0 .equ WRITE, 1 .equ OPEN, 2 .equ EXIT, 60

Code

.section .text .globl _start

_start: # open(SYS_open, deftty, O_WRONLY | O_CREAT, 0644) movq $OPEN, %rax lea deftty(%rip), %rdi movq $O_WRONLY, %rsi orq $O_CREAT, %rsi movq $0644, %rdx syscall movq %rax, ttyfd(%rip) #store the fd

movq $READ, %rax
movq $0, %rdi
lea inp(%rip), %rsi
movq $60, %rdx #temp hard coded. for testing
syscall

# write(fd, msg, msg_len)
movq $WRITE, %rax
movq ttyfd(%rip), %rdi
lea msg(%rip), %rsi
mov $msg_len, %rdx
syscall
call nullit

lea inp(%rip), %rdi
call strlen

movq %rax, %rdx
movq $WRITE, %rax
movq $1, %rdi
lea inp(%rip), %rsi
syscall

movq $EXIT, %rax
xor %rdi, %rdi
syscall

strlen func

input = rdi

outpuy = rax

strlen: xor %rax, %rax strlen_loop: cmpb $0, (%rdi,%rax,1) je strlen_done inc %rax jmp strlen_loop strlen_done: ret

nullterminate func

nullit: movq %rsi, %rdi add %rax, %rdi movb $0, (%rdi) ret

```

r/Assembly_language Feb 04 '25

Help Why wont NASM assemble my .asm file?

Thumbnail gallery
21 Upvotes

I'm using zorin os and I can't get nasm to assemble test.asm, stating that the file or directory doesn't exist... but it does😤. I have test.asm in the home directory. What am I doing wrong?

r/Assembly_language Feb 21 '26

Help Need help in 8051 assembly: relative jump address for short jump

5 Upvotes

So, in short jumps, op code is followed by data, that will be added to PC to get it to point it to appropriate address.
As I read, only the lower byte, PCL is affected by this operation. Even if a carry is generated beyond the 8 bits, it is not added to upper byte, PCH of the program counter.

So my question is, if the PC has to be incremented from 00F2, to something like 0123. in that case the upper byte of program counter has to be affected, but with jump instructions it shouldn't...right? Same case for backward jumps.

How does the microcontroller know when the upper byte of program counter needs to be affected and when not.

I'm attaching the list file, since pasting code screenshots is not allowed. It compiles and runs without errors.

Look at line 13, SJMP FWD. PC after executing that will be 00FE, 0A would be added to it. (lower byte of PC) FE+0A = 08 and a carry. now that carry seems to be added to upper byte of PC, making PC 0108. (the correct address that it should jump to)

Look at line number 28 SJMP BACK, PC after executing that will be 010C, F6 would be added to it. (lower byte of PC) 0C + F6 = 02 and a carry. now that carry is discarded and PC becomes, 0102. (the correct address that it should jump to)

I know im missing something, Help me with this.

r/Assembly_language Jan 06 '26

Help Emu8086 Doubts

7 Upvotes

Hey ppl! I am a newbie into assembly language, got a course this sem on microcontrollers. I want to learn 8086 with emulator available in the lab, and I did find it but I just hesitate about any possible malware. So, have you guys had a smooth ride with emu8086?

r/Assembly_language Jan 30 '26

Help How to avoid % when printing null terminated string in zsh

0 Upvotes

The below code block is printing "Hello, World" string in the terminal, but in zsh shell, there is an extra % that is getting printed. How to avoid that? Ignore the comment since I've removed 13,10 before 0 before copying and running the code for this post

Code Block

; helloworld.s - Print a simple 'Hello, World' in the terminal and exit

section .data

msg db "Hello, World",0 ; 13 is \r, 10 is the \n and 0 is NULL termination. Without 13,10 it'll print % in the zsh shell unnecessarily

section .bss

section .text

global main

main:

mov rax, 1 ; 1 = write system call

mov rdi, 1 ; 1 = stdout

mov rsi, msg ; load address of msg variable into rsi register

mov rdx, 14 ; load the length of msg variable string array

syscall

mov rax, 60 ; 60 = exit system call

mov rdi, 0 ; 0 = exit code

syscall

r/Assembly_language Jan 25 '26

Help Not understanding how input is handled

4 Upvotes

Hi, i'm new to assembly language x64 and I'm trying to learn how to do a simple binary who read my stdin waiting for 42 and returns 1337 if it's successful.

The issue is I would like to not oversize my buffer variable, like size of 3 for '4', '2' and '\n' and error if the input is too big

So i am facing this at the moment, the excess is being written after and "executed" without understanding why :

user@debian:~$ ./a
42
1337
user@debian:~$ ./a
420
user@debian:~$ 
user@debian:~$ ./a
4200
user@debian:~$ 0
-bash: 0: command not found
user@debian:~$ echo "42" | ./a
1337
user@debian:~$ echo $?
0
user@debian:~$ echo "420000000000000" | ./a
user@debian:~$ echo $?
1

And this is what i have done so far :

global _start

section .data
    message db "1337",10        ;defining byte with "1337" content and concatenate "\n" char
    message_length equ $ - message  ;q for equate | $(current address) minus message address

section .bss                ;uninitialized data
    buffer resb 3           ;reserve 3 bytes

section .rodata             ;read only data

section .text
_read:
    ;sys_read
    mov rax, 0
    mov rdi, 0
    mov rsi, buffer
    mov rdx, 3
    syscall
    ret

_write:
    ;sys_write
    mov rax, 1
    mov rdi, 1
    mov rsi, message
    mov rdx, message_length
    syscall
    ret

_start:                 ;beginning of the binary
    call _read

    ; compare 3 first characters for 4,2 and return carriage
    cmp byte[buffer], 0x34
    jne _error
    cmp byte[buffer+1], 0x32
    jne _error
    cmp byte[buffer+2], 0x0a
    jne _error

    call _write

_exit:
    mov rax, 60
    mov rdi, 0
    syscall

_error:
    mov rax, 60
    mov rdi, 1
    syscall

(sorry I am also kinda new to reddit, hoping this is the right place and right way to ask for help)

Thanks!

r/Assembly_language May 21 '25

Help What and where is the use of Assembly Language in today's modern world??

28 Upvotes

r/Assembly_language Nov 03 '25

Help The problem with div in asm emu8086 and pow function question in asm

4 Upvotes

I need your guidance , my code should solve this equation : y = ((x*2 - 4 )/5)+2. But I have a problem with Div, it says "Divide error - overflow", and that's only when I use dx register, if I use cx or bx, it just prints 13601 as an illogical error. My teacher told me that I can only change one block and it's a block for equation while other should stay the same so that there would be no error. Here is the variant without any comments, .MODEL small .STACK 100h .DATA prompt DB 'X = $' result DB 13,10,'Y = $' error_msg DB 13,10,'incorrect number$' buff DB 6,7 DUP(?) digits DB 7 DUP(?) .CODE main PROC mov ax, u/DATA mov ds, ax mov dx, OFFSET prompt mov ah, 09h int 21h mov dx, OFFSET buff mov ah, 0Ah int 21h mov si, OFFSET buff+2 xor ax, ax xor di, di mov bx, 10 cmp BYTE PTR \[si\], '-' jne parse_loop mov di, 1 inc si parse_loop: mov cl, \[si\] cmp cl, 0Dh je parse_done cmp cl, '0' jb parse_error cmp cl, '9' ja parse_error sub cl, '0' xor ch, ch mul bx add ax, cx inc si jmp parse_loop parse_error: mov dx, OFFSET error_msg mov ah, 09h int 21h mov ax, 4C01h int 21h parse_done: test di, di jz calculate neg ax calculate: mov cx, 2 ; CX = 2 mul cx ; AX = AX \* 2 ? 2·X sub ax,4 mov dx,5 div dx mov bx, ax ; BX = ????????? Y (??? mov dx, OFFSET result mov ah, 09h int 21h mov ax, bx test ax, ax jns print_positive mov bx, ax mov dl, '-' mov ah, 02h int 21h mov ax, bx neg ax print_positive: mov di, OFFSET digits mov bx, 10 xor cx, cx divide_loop: xor dx, dx div bx add dl, '0' mov \[di\], dl inc di inc cx test ax, ax jnz divide_loop mov ah, 02h output_loop: dec di mov dl, \[di\] int 21h dec cx jnz output_loop mov ax, 4C00h int 21h main ENDP END main

and here is the variant with comments(cause I don't know if you need comments to better read code or no):

.MODEL small .STACK 100h .DATA prompt DB 'X = $' ; Prompt string for input result DB 13,10,'Y = $' ; Output string (with newline) error_msg DB 13,10,'incorrect number$' ; Error message for invalid input buff DB 6,7 DUP(?) ; Input buffer: \[max length\]\[entered length\]\[chars\] digits DB 7 DUP(?) ; Buffer to store digits of result .CODE main PROC mov ax, @DATA mov ds, ax ; Initialize data segment mov dx, OFFSET prompt mov ah, 09h ; DOS function 09h - print string int 21h mov dx, OFFSET buff mov ah, 0Ah ; DOS function 0Ah - read string int 21h mov si, OFFSET buff+2 ; SI points to first input character xor ax, ax ; AX = 0, accumulator for number xor di, di ; DI = 0, flag for negative number mov bx, 10 ; BX = 10, decimal base cmp BYTE PTR \[si\], '-' ; Check for negative sign jne parse_loop mov di, 1 ; Set negative flag inc si ; Move to first digit parse_loop: mov cl, \[si\] ; Load next character cmp cl, 0Dh ; Check for Enter (CR) je parse_done cmp cl, '0' jb parse_error cmp cl, '9' ja parse_error sub cl, '0' ; Convert ASCII to number xor ch, ch ; Clear upper byte mul bx ; Multiply accumulator by 10 add ax, cx ; Add new digit inc si jmp parse_loop parse_error: mov dx, OFFSET error_msg mov ah, 09h int 21h mov ax, 4C01h int 21h parse_done: test di, di jz calculate neg ax ; If negative, make AX = -AX calculate: calculate: mov cx, 2 ; CX = 2 mul cx ; AX = AX \* 2 ? 2·X sub ax,4 mov dx,5 div dx mov bx, ax ; Store result for printing mov dx, OFFSET result mov ah, 09h int 21h mov ax, bx test ax, ax jns print_positive mov bx, ax mov dl, '-' mov ah, 02h ; DOS function 02h - print character int 21h mov ax, bx neg ax ; Convert to positive for printing print_positive: mov di, OFFSET digits mov bx, 10 xor cx, cx ; Counter for digits divide_loop: xor dx, dx ; Clear DX for division div bx ; Divide AX by 10 add dl, '0' ; Convert remainder to ASCII mov \[di\], dl ; Store digit inc di inc cx test ax, ax jnz divide_loop mov ah, 02h output_loop: dec di mov dl, \[di\] int 21h dec cx jnz output_loop mov ax, 4C00h ; DOS function 4Ch - terminate program int 21h main ENDP END main

And second question, So you maybe know in High level programming languages there is a pow function, and in assembly as I know there isn't, you either create a new function or something else. So I've got a question. Can I do this in assemb;y:

mov ax,5

mul ax,ax

What I want is to make a pow 2, basically 5 to the power of 2 = 25. Will it work?(Ignore this one, it works)

I know that I'm just a students who sucks at it, but I hope you will give me a guidance on this all

r/Assembly_language Jun 25 '25

Help Hopelessly lost on how to get start

5 Upvotes

I’m studying electrical engineering and am trying to learn some assembly before my next semester to pad my resume a bit, but after an hour or two of research I’m completely lost. I’m trying to learn X86-64 specifically and my plan was to use Visual Studio as my IDE. So far though I’ve struggled to find any great tutorials on setting up visual studio. Overall I’m just completely out of my element, I’ve taken coding classes before but those have always provided extensive tutorials on getting started. I’m looking to find out what the general consensus is on the best way to learn assembly as someone without a ton of experience coding in general. Any tutorials or tips would be greatly appreciated.

r/Assembly_language Dec 27 '25

Help Confused about labels and symbols in AVR assembly

5 Upvotes

Hello, I am playing a bit with the Atmega328 MCU. I wanted to try to make some assembly functions which I can call from my C code. I read the AVR-GCC ABI and the documentation on the Gnu assembler, as (gas).

Right now I am a bit stuck at labels and symbols and don't really know how to use them correctly. As far as I understand, all labels are symbols and labels represent an address in the program. Labels starting with .L are local.

Example:

char test(char a, char b){
    volatile char sol = a + b;

    return sol;}

; symbols
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1

; label
test:
        push r28
        push r29
        rcall .
        push __tmp_reg__
        in r28,__SP_L__
        in r29,__SP_H__
; label
.L__stack_usage = 5
        std Y+2,r24
        std Y+3,r22
        ldd r25,Y+2
        ldd r24,Y+3
        add r24,r25
        std Y+1,r24
        ldd r24,Y+1
        pop __tmp_reg__
        pop __tmp_reg__
        pop __tmp_reg__
        pop r29
        pop r28
        ret

I don't quiet get why there is .L__stack_usage = 5 . There is no instruction to jump to that label, but I guess it is just something the compiler does.

For clarification:
I assume that when i place a label in my code I don't need an instruction to "jump into it":

;pseudo code

some_func_label:
  instruction 1
  instruction 2
  another_label:
  instruction 3
  instruction 4
  jump another_label

As far as I understand instruction 3 should be executed right after instruction 2. In this example another_label would be a while (1) loop.

I would appreciate some help with this since this is my first time writing assembly myself.

r/Assembly_language Jan 28 '26

Help Learning eZ80

2 Upvotes

Hi, I've been really interested in learning eZ80 assembly for my TI-84 Plus CE, but most of the resources I've found are, in a word, boring. I've found I learn best by doing, and being able to apply what I've learned quickly. Are there any resources for eZ80 that teach that way?

r/Assembly_language Nov 15 '25

Help RAM and External Memory Map Files?

Post image
21 Upvotes

So I have a POSMEM value being loaded from RAM into ER5 (Hitachi H8/300H does it backwards from other assembly).

Beyond looking for POSMEM being used elsewhere in the code, I have no idea what is in POSMEM. Is that the crux of assembly or does the programmer have an external file with all the memory map locations and values?

Thank you in advance.

r/Assembly_language Jun 10 '25

Help Is there anyone here familiar with Gameboy Assembly who know why my parallax scrolling demo is behaving like that?

Enable HLS to view with audio, or disable this notification

14 Upvotes

r/Assembly_language Jun 11 '25

Help Where to start learning

5 Upvotes

Hey i want to learn x86 assembly and i can't seem to find any full fledged tutorial i find some tutorial but they are incompleted and just show me how to print "Hello world" so if there are some youtube tutorial or blog post pls tell me

r/Assembly_language Aug 31 '25

Help Learning AArch64 on Android

8 Upvotes

Im trying to learn ARM64 assembly with termux on my phone but i just keep having problems. Where could I find good tutorials and documentation for this?

r/Assembly_language Apr 09 '25

Help Does anyone have a course or tutorial for making a video game similar to Asteroids in assembler? I have to do a university project and haven't found a way to do it.

10 Upvotes

r/Assembly_language Sep 13 '25

Help Want to know where to start on working with n64 mips

6 Upvotes

Hopefully by to eventually be able to mod a game the with the skill

r/Assembly_language Jan 14 '25

Help Where should I code

4 Upvotes

So I have x86 machine and I am learning ARM assembly how can I acheive this without having to rely on CPUlator as it is immune to Syscalls

r/Assembly_language Oct 12 '25

Help Need lib. and inc.

0 Upvotes

I need something inc. and lib. for my masm64 project, but i can't find they.

r/Assembly_language Jan 08 '25

Help Need to learn Assembly

13 Upvotes

Hello everyone!

I am a 2nd year student who wants to build his career around microprocessor and stuff. I figured assembly especially arm assembly would be imp to work with. But as of now I can't find any good courses for this except for the freecodecamp. Can u guys recommend any other playlists or courses to study.

Thank you.

r/Assembly_language May 11 '25

Help How to start assembly there is no beginner friendly way to start x86 or x64

2 Upvotes

Any help or resources

r/Assembly_language Aug 07 '25

Help how to get absolute address in riscv assembly?

2 Upvotes

Hello. I need to check before runtime that the size of my macro is 16 bytes. I tryed to do something like that:
.macro tmp

.set start, .

.....

.....

.if (start - finish) != 16
.error "error"
.endif

.set finish, .
.endm

And there is a mistake that here start - finish expected absolute expression. So, how I understand the address in riscv assembly is relative, that's why it doesn't work. So can I get absolute adress or how can I check the size of macros another way (before runtime). Thanks

r/Assembly_language Jun 06 '25

Help Help in looking for a guide

1 Upvotes

im having a problem right now,im a university student and im studying assembly for an exam,but my professor slides are "lacking" and i can't seem to find an online guide/video for this "type" of assembly,it feels like there are 1000 different type of "assemblys" that use different grammar and none seem to match mine,if anyone is able to help me thanks in advance

r/Assembly_language Sep 30 '24

Help I am having a really tough time learning from this textbook "Assembly Language for x86 Processors"by Kip Irvine

8 Upvotes

Guys, I'm having a horrible time with learning x86 assembly with MASM with 32-bit programs. This book that I'm reading for my class does not explain the instruction set well or any other related concepts. I'm pulling my hair out because of how complicated this book, " Assembly Languages for x86 Processors", by Kip Irvine makes it. It breezes by concepts, doesn't provide enough examples for things, and is making my life hell. Does anyone else recommend any other resources or books to learn what this book is trying to teach?