Getting compile errors with this.
undefined reference to all the "C" functions
In 64-bit shouldn't all the calls be changed to "syscall"
Generally I try to avoid the stack like the plague.
Only use it for pushes and pop.
I think I see how you avoid the stack hassle by using
stack align and stack restore.
Why can't I use the registers instead of the stack?
Could I possibly have "glibc" in the wrong place?
I put the demo64 program in home/jack/nasmfld
This is what I get when running gcc -o demo64 demo64.o -lcurses nasmbld:
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o:/build/eglibc-3GlaMS/eglibc-2.19/csu/../sysdeps/x86_64/start.S:118: first defined here
collect2: error: ld returned 1 exit status
Got these errors using: ld -o demo64 demo64.o in home/jack/nasmfld:
jack@jack-myheadache ~/nasmfld $ ld -o demo64 demo64.o:
demo64.o: In function `do_init':
demo64.asm:(.text+0x14): undefined reference to `signal'
demo64.asm:(.text+0x19): undefined reference to `initscr'
demo64.o: In function `do_init.CursesInitSuccessful':
demo64.asm:(.text+0x3f): undefined reference to `keypad'
demo64.asm:(.text+0x44): undefined reference to `nonl'
demo64.asm:(.text+0x49): undefined reference to `cbreak'
demo64.asm:(.text+0x4e): undefined reference to `echo'
demo64.asm:(.text+0x53): undefined reference to `has_colors'
demo64.o: In function `do_init.HasColorSupport':
demo64.asm:(.text+0x68): undefined reference to `start_color'
demo64.asm:(.text+0x7c): undefined reference to `init_pair'
demo64.asm:(.text+0x90): undefined reference to `init_pair'
demo64.asm:(.text+0xa9): undefined reference to `newwin'
demo64.o: In function `do_exit':
demo64.asm:(.text+0xc4): undefined reference to `refresh'
demo64.asm:(.text+0xc9): undefined reference to `endwin'
demo64.asm:(.text+0xd0): undefined reference to `exit'
demo64.o: In function `clear_blue':
demo64.asm:(.text+0xef): undefined reference to `wbkgd'
demo64.asm:(.text+0xfc): undefined reference to `wrefresh'
demo64.o: In function `draw_child_window':
demo64.asm:(.text+0x117): undefined reference to `wbkgd'
demo64.asm:(.text+0x124): undefined reference to `wrefresh'
demo64.o: In function `get_user_input':
demo64.asm:(.text+0x149): undefined reference to `wgetnstr'
jack@jack-myheadache ~/nasmfld $
;------------------------------------------------
; 2-23-2016 using NASM 64
; Order of colors: BGR
;
; Bryants goodies
; Use Case:
; - create a full screen of a light blue color.
; - put a small rectangle on the screen in yellow.
; - let the user enter 4 digits in black in that rectangle.
; - read the 4 digits from the rectangle.
; Dependencies:
; libc-dev - GNU C library.
; libncurses-dev - Developer's libraries for ncurses.
; Build Process:
; nasm -f elf64 demo64.asm -o demo64.o
; gcc -o demo64 demo64.o -lcurses
; Run Process:
; ./demo64
bits 64
cpu IA64
global main
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions from the Standard C Library
extern signal
extern atoi
extern exit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions from the NCurses Library
extern initscr
extern keypad
extern nonl
extern cbreak
extern echo
extern has_colors
extern start_color
extern init_pair
extern newwin
extern endwin
extern refresh
extern wrefresh
extern wgetnstr
extern wbkgd
extern LINES
extern COLS
%define SIGINT 2 ; defined in signal.h
%define TRUE 1 ; defined in curses.h
%define FALSE 0 ; defined in curses.h
%define COLOR_BLACK 0
%define COLOR_RED 1
%define COLOR_GREEN 2
%define COLOR_YELLOW 3
%define COLOR_BLUE 4
%define COLOR_MAGENTA 5
%define COLOR_CYAN 6
%define COLOR_WHITE 7
%define COLOR_PAIR(n) ((n) << (
)
%define BLACK_ON_BLUE 1
%define BLACK_ON_YELLOW 2
%define BLACK_ON_BLUE 1
%define BLACK_ON_YELLOW 2
%define STACK_ALIGN sub rsp, 8
%define STACK_RESTORE add rsp, 8
section .data
hWindow: dq 0
hChildWindow: dq 0
szUserInput: db 0, 0, 0, 0, 0
section .text
global _start ;??
_start: ;??
;; do_init : nothing -> boolean .
;; preform all of the applications initialization.
;; when initialization was successful, hWindow will
;; contain the curses screen handle and the return
;; value will be TRUE. otherwise, it returns FALSE.
do_init:
STACK_ALIGN
;; setup an interrupt to terminate
mov rsi,do_exit
mov rdi,SIGINT
call signal
;; initialize the curses library
call initscr
;; was curses initialization successful?
cmp rax,0
jne .CursesInitSuccessful
;; initialization failed, return FALSE
mov rax,FALSE
ret
.CursesInitSuccessful:
;; save a copy of curses root window
mov [hWindow],rax
;; enable keyboard mapping
mov rsi,TRUE
mov rdi,[hWindow]
call keypad
;; tell curses not to translate LF into CRLF on output
call nonl
;; take input chars one at a time, no waiting for newline
call cbreak
;; enable echoing of input
call echo
;; does this system support color terminals?
call has_colors
cmp rax,0
jne .HasColorSupport
;; No color support, return FALSE
STACK_RESTORE
mov rax,FALSE
ret
.HasColorSupport:
call start_color
;; create our color pairs
;; black foreground, blue background
mov rdx, COLOR_BLUE
mov rsi, COLOR_BLACK
mov rdi, BLACK_ON_BLUE
call init_pair
;; black foreground, yellow background
mov rdx, COLOR_YELLOW
mov rsi, COLOR_BLACK
mov rdi, BLACK_ON_YELLOW
call init_pair
;; lets create a child window
mov rcx, 50 ; x value
mov rdx, 10 ; y value
mov rsi, 5 ; 5 columns for 4 digits
mov rdi, 1 ; 1 line for 1 row of digits
call newwin
mov [hChildWindow],rax
;; if we reach this point, we have initialized successfully.
STACK_RESTORE
mov rax,TRUE
ret
;; do_exit : integer -> nothing .
;; exit to the operating system.
do_exit:
STACK_ALIGN
;; refresh our screen
call refresh
;; shut down curses
call endwin
;; return to operating system
push qword 0
call exit
add rsp,4
;; we should never reach this point
STACK_RESTORE
ret
;; clear_blue : nothing -> nothing .
;; create a full screen of a light blue color.
clear_blue:
STACK_ALIGN
;; make our background blue
mov rsi,COLOR_PAIR(BLACK_ON_BLUE)
mov rdi,[hWindow]
call wbkgd
;; refresh our screen
mov rdi, [hWindow]
call wrefresh
STACK_RESTORE
ret
;; draw_child_window : nothing -> nothing .
;; put a small rectangle on the screen in yellow.
draw_child_window:
STACK_ALIGN
;; make our background yellow
mov rsi, COLOR_PAIR(BLACK_ON_YELLOW)
mov rdi, [hChildWindow]
call wbkgd
;; refresh our child window
mov rdi,[hChildWindow]
call wrefresh
STACK_RESTORE
ret
;; get_user_input : nothing -> integer .
;; let the user enter 4 digits in black in that rectangle.
get_user_input:
STACK_ALIGN
;; get user input
mov rdx, 4
mov rsi, szUserInput
mov rdi, [hChildWindow]
call wgetnstr
;; convert string to integer
;; rdi, rsi, rdx, rcx, r8, r9
mov rdi,szUserInput
call atoi
STACK_RESTORE
ret
;; main : integer (string . string) -> integer .
;; our program starts here.
main:
STACK_ALIGN
call do_init
cmp rax,TRUE
jne .done
;; clear the screen to blue
call clear_blue
;; draw yellow window
call draw_child_window
;; get user input
call get_user_input
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; At this point in our code, the number we ;;
;; entered into our child window is in the ;;
;; RAX register. We can now use it for any- ;;
;; thing we want. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.done:
STACK_RESTORE
xor rdi, rdi
call do_exit
ret