NASM: Register

Register

Data Registers

  • AX: primary ACCUMULATOR.
  • BX: BASE register.
  • CX: COUNT register.
  • DX: DATA register.

32bit: eax, ebx, ecx, edx

Pointer Registers

  • Instruction Pointer (IP) stores the offset addr of next instruction, in association with CS register(CS: IP)
  • Stack Pointer (SP) provides offset value within the program stack. SS:SP gives current position of data or address within the program stack.
  • Base Pointer (BP) helps in referencing params passed to a subroutine.

32bit: esp, ebp

Index Registers

Source Index (SI) is used as souce index for string opts and Destination Index (DI) as destination index.

Control Registers

skipped.

Segment Registers

Three main segs:

  • Code Segment
  • Data Segment
  • Stack segment

Demo

section .text
        global main
        global _start
main:
_start:
        mov edx, len ; edx: data register
        mov ecx, msg ; ecx: count register
        mov ebx, 1      ; file descriptor, ebx: base register
        mov eax, 4      ; system call number (sys_write)
        int 0x80        ; call kernel

        mov edx, 9      ; message length
        mov ecx, s2     ; message to write
        mov ebx, 1      ; file descriptor
        mov eax, 4      ; system call number (sys_write)
        int 0x80        ; call kerel
        mov eax, 1      ; sys call number (sys_exit)
        int 0x80        ; call kernel

section .data
msg db 'Displaying 9 starts', 0xa       ; a message
len equ $ - msg         ; length o f msg
s2 times 9 db '*'
Written with StackEdit.

发表留言

本站启用了垃圾评论检测插件,如果误删请联系我~