Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
lecture6-1
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
;File: index1.asm ; ;This program demonstrates the use of an indexed addressing mode ;to access array elements ; ;This program has no I/O. Use the debugger to examine its effects ; ;nasm -felf64 -g index1.asm -o index1.o ;ld -o index1 index1.o ; section .data arr: dd 0,1,2,3,4,5,6,7,8,9 ; ten 32-bit words base: equ arr - 4 section .text global _start _start: ;Add 5 to each element of the array stored in arr ;Simulate ; ; for (i=0; i<10l i++) { ; arr[i] += 5; ; } init: mov rcx,0 ;rcx simulates i loop1: cmp rcx,10 ; i<10 jge done1 add [rcx*4+arr], dword 5 ; arr[i] += 5 inc rcx ; i++ jmp loop1 done1: ;another way init2: mov rcx,9 ; i=9 loop2: add [rcx*4+arr], dword 5 ; arr[i] += 5 dec rcx ; i-- jge loop2 ; loop while rcx >= 0 ;another way init3: mov rdi,base ; base computed by ld mov rcx,10 ; i = 10 loop3: add [rdi+rcx*4], dword 5 ; arr[i] += 5 loop loop3 ; loop = dec rcx, jne alldone: mov rax,60 xor rdi,rdi syscall
Show compiler warnings
[
+
]
Show input
edit mode
|
history
|
discussion