Online Assembler (NASM) Compiler
Online Assembler (NASM) Compiler
1 ; Welcome to JDoodle!
2 ;
3 ; You can execute code here in 88 languages. Right now you’re in the NASM IDE.
4 ;
5 ; 1. Click the orange Execute button ▶ to execute the sample code below and see how it works.
6 ; 2. Want help writing or debugging code? Type a query into JDroid on the right hand side ---------------->
7 ; 3. Try the menu buttons on the left. Save your file, share code with friends and open saved projects.
8 ;
9 ; Want to change languages? Try the search bar up the top.
10
11 section .data
12 test_var dd 0 ; Define a 4-byte (32-bit) variable in memory initialized to 0
13
14 section .text
15 global _start
16
17 _start:
18 ; Initialize registers
19 mov ecx, 1000000 ; Set loop counter to 1 million; ecx is general register
20
21 ; Start timing
22 rdtsc ; Read Time-Stamp Counter (start time)
23 ;64-bit register that continuously increments and counts the number of clock cycles
24 mov ebx, eax ; Store the start time (low 32 bits of cycle count) in ebx
25
26 ; Access memory in a loop
27 access_loop:
28 mov eax, [test_var] ; Read the value of test_var into eax
29 add eax, 1 ; Perform a simple operation (increment eax)
30 mov [test_var], eax ; Write the modified value back to test_var
31 loop access_loop ; Decrement ecx and repeat if not zero
32
33 ; Stop timing
34 rdtsc ; Read Time-Stamp Counter (end time)
35 sub eax, ebx ; Subtract start time (in ebx) from end time (in eax)
36 ; eax now contains the total cycles for the loop
37
38 ; Exit
39 mov ebx, eax ; Move the cycle count result into ebx for exit status
40 mov eax, 1 ; Syscall number for exit in Linux
41 int 0x80 ; Invoke syscall to exit
42
Twitter
I have a suggestion
https://www.jdoodle.com/compile-assembler-nasm-online 1/1