Search code examples
assemblyx86additionnasmmov

Assembly : add two numbers


I would like to add two number num1B and num2B and store the number in result, finaly show result.

But, when i launch nasm, it says :

prog2_1.txt:4: warning: attempt to initialize memory in a nobits section: ignored

prog2_1.txt:5: warning: attempt to initialize memory in a nobits section: ignored

prog2_1.txt:6: warning: attempt to initialize memory in a nobits section: ignored

my code :

org 0x0100 ;

section .bss
    num1B: db 0Ah ; init num1B to 0Ah
    num2B: db 00111111b ; init num2B to 00111111b
    result: db 0 ; init result to 0

section .data

section .text

    mov AX,0 ; AX = 0
    add AX,[num1B] ; AX = AX + num1B
    add AX,[num2B] ; AX = AX + num2B
    mov [result],AX ; result = result + AX

    mov DX,[result] ; show result
    mov AH,09h
    int 21h

    mov AH,4Ch
    int 21h

Thank you


Solution

  • You need to change your .bss section to .data section. The .bss section is meant for uninitialized data, while the .data section is meant for initialized data. That's why you can't use db, dw and so forth in .bss section. Instead, you can place them in .data section. Similarly, you can use resb. resw and so forth in .bss section but not in .data section.

    In short, .data is for initialized data and .bss is for uninitialized data.