summaryrefslogtreecommitdiff
path: root/rdoff/test/rdtmain.asm
diff options
context:
space:
mode:
authorAnas Nashif <anashif@tizendev.org>2012-05-23 08:22:02 +0900
committerGerrit Code Review <gerrit2@localhost>2012-05-23 08:22:02 +0900
commitb9fae45f49f97914a89b763028f5dbf8b70a9cbc (patch)
treea76f72f9a6d751f31456309e3cfdf3022b6c5546 /rdoff/test/rdtmain.asm
parentecc629773ccf1eaae669dce3d2b017ed476ce911 (diff)
parentb9fad1ab2ad3bd87bff05c4688c978d582ada438 (diff)
downloadnasm-b9fae45f49f97914a89b763028f5dbf8b70a9cbc.tar.gz
nasm-b9fae45f49f97914a89b763028f5dbf8b70a9cbc.tar.bz2
nasm-b9fae45f49f97914a89b763028f5dbf8b70a9cbc.zip
Merge " Upstream version 2.08rc7"
Diffstat (limited to 'rdoff/test/rdtmain.asm')
-rw-r--r--rdoff/test/rdtmain.asm47
1 files changed, 47 insertions, 0 deletions
diff --git a/rdoff/test/rdtmain.asm b/rdoff/test/rdtmain.asm
new file mode 100644
index 0000000..626a2e2
--- /dev/null
+++ b/rdoff/test/rdtmain.asm
@@ -0,0 +1,47 @@
+ ;; rdtmain - main part of test program for RDX execution.
+ ;; returns true (0) if its parameter equals the phrase "hello"
+ ;; "hello" is stored in the library part, to complicate the
+ ;; linkage.
+
+ ;; assemble and link with the following commands:
+ ;; nasm -f rdf rdtmain.asm
+ ;; nasm -f rdf rdtlib.asm
+ ;; ldrdf rdtmain.rdf rdtlib.rdf -o rdxtest.rdx
+
+ ;; run with 'rdx rdxtest.rdx [parameters]' on a Linux (or possibly
+ ;; other 32 bit OS) systems (x86 architectures only!)
+ ;; try using '&& echo Yes' afterwards to find out when it returns 0.
+
+[EXTERN _strcmp] ; strcmp is an imported function
+[EXTERN _message] ; imported data
+[SECTION .text]
+[BITS 32]
+
+ ;; main(int argc,char **argv)
+[GLOBAL _main]
+_main:
+ push ebp
+ mov ebp,esp
+
+ ;; ebp+8 = argc, ebp+12 = argv
+
+ cmp dword [ebp+8],2
+ jb error ; cause error if < 1 parameters
+
+ mov eax, [ebp+12] ; eax = argv
+
+ mov ebx, [eax+4] ; ebx = argv[1]
+ mov ecx, _message ; ecx = "hello"
+
+ push ecx
+ push ebx
+ call _strcmp ; compare strings
+ add esp,8 ; caller clears stack
+
+ pop ebp
+ ret ; return return value of _strcmp
+
+error:
+ mov eax,2 ; return 2 on error
+ pop ebp
+ ret