Skip to content

Commit

Permalink
Improve the NASM visual sample (#1421)
Browse files Browse the repository at this point in the history
This commit improves the consistency of the NASM visual sample.
  • Loading branch information
bernardosulzbach authored Feb 5, 2020
1 parent 39b0ed7 commit 5896d00
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
12 changes: 6 additions & 6 deletions lib/rouge/demos/nasm
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
extern irq_handler

irq_common_stub:
pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov ax, ds ; Lower 16-bits of eax = ds.
push eax ; save the data segment descriptor
mov ax, 0x10 ; load the kernel data segment descriptor
mov edx, eax
call irq_handler
pusha ; push all general-purpose registers
mov ax, ds ; lower 16-bits of eax = ds
push eax ; save the data segment descriptor
mov ax, 0x10 ; load the kernel data segment descriptor
mov edx, eax
call irq_handler

%assign i 0
%rep 8
Expand Down
58 changes: 30 additions & 28 deletions spec/visual/samples/nasm
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
;Simple test of NASM parser
; Simple test of the NASM parser

SECTION .data ; Data section, initialized variables
; Data section, initialized variables
SECTION .data

fmt: db "a=%d, eax=%d", 10, 0 ; The printf format, "\n",'0'
a: dd 5 ; int a=5;
fmt: db "a=%d, eax=%d", 10, 0 ; the printf format
a: dd 5 ; int a = 5

%macro IRQ 2
global irq%1
Expand All @@ -14,36 +15,37 @@ a: dd 5 ; int a=5;
jmp irq_common_stub
%endmacro

extern printf ; the C function, to be called
extern printf ; the C function to be called

SECTION .text ; Code section.
; Code section
SECTION .text

global main ; the standard gcc entry point
global main ; the standard gcc entry point

main:
push ebp
mov ebp,esp
mov eax, [a]
add eax, 2
push 'a'
push dword [a] ; value of variable a
push dword fmt ; address of ctrl string
call printf ; Call C function
add esp, 12
mov esp, ebp ; takedown stack frame
pop ebp
mov eax,0 ; normal, no error, return value
ret ; return
push ebp
mov ebp, esp
mov eax, [a]
add eax, 2
push 'a'
push dword [a] ; value of variable a
push dword fmt ; address of ctrl string
call printf ; call C function
add esp, 12
mov esp, ebp ; takedown stack frame
pop ebp
mov eax, 0 ; normal, no error, return value
ret ; return

irq_common_stub:
pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov ax, ds ; Lower 16-bits of eax = ds.
mov ax, 0x10 ; load the kernel data segment descriptor
mov ds, ax
popa ; Pops edi,esi,ebp,esp,ebx,edx,ecx,eax
add esp, 8 ; Cleans up the pushed error code and pushed irq number
sti ; (re)Enable interrupts "set interrupt flag"
iret ; pops CS, EIP, EFLAGS, SS, and ESP
pusha ; pushes all general-purpose registers
mov ax, ds ; lower 16-bits of eax = ds
mov ax, 0x10 ; load the kernel data segment descriptor
mov ds, ax
popa ; pops all general-purpose registers
add esp, 8 ; cleans up the pushed error code and pushed irq number
sti ; (re)-enable interrupts "set interrupt flag"
iret ; pops CS, EIP, EFLAGS, SS, and ESP

%assign i 0
%rep 16
Expand Down

0 comments on commit 5896d00

Please sign in to comment.