Author Topic: Getting started.  (Read 11752 times)

Offline epl692

  • Jr. Member
  • *
  • Posts: 2
Getting started.
« on: July 15, 2016, 04:09:29 PM »
So I have been trying to learn the basics of nasm programing. I started by using http://forum.nasm.us/index.php?topic=2062.0 as a base. I am trying to capture text from the user and put it into memory. I just can't seem to figure out how to mov it.
Code: [Select]
;--------------------------------------------
; Copyright (c)2015,2016 Soffian Abdul Rasad
; All rights reserved
; For Linux64 - Arguments in RAX,RBX,...
;       - Return in RAX,RBX...
; Read licence.txt
;--------------------------------------------
; Compile : nasm -f elf64 thisfile.asm
; Link   : ld thisfile.o -o thisfile
; Run   : ./thisfile
;--------------------------------------------
global _start

section .data
msg db 'Hello world,',0
welcome db 'This is Eric',0
prompt1 db 'What is your name? ',0

s dq 45.667


section .bss
dummy resq 1
name resw 10

section .text
_start:

mov rax,msg
call prnstrz
call newline
mov rax,welcome
call prnstrz
call newline
mov rax,prompt1
call prnstrz
call readstr
;; text is kept in rax
;; mov [name],rax
mov rax,name
call newline
call prnstrz
call newline
;practice coding here


call exit
...
Full Source: http://sdf.org/~epl692/eric.asm

Offline soulvomit

  • Jr. Member
  • *
  • Posts: 31
Re: Getting started.
« Reply #1 on: July 18, 2016, 07:40:10 AM »
Hi,

readstr is not part of the source code you linked? where do you get this subroutine from?

Cheers

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: Getting started.
« Reply #2 on: July 24, 2016, 03:55:34 AM »
readstr is not part of the source code you linked? where do you get this subroutine from?

It's in the updated version of stressful's code (same thread):

Code: [Select]
prnchr
prnchrs
prnchar
prnstr        
prnstrz
prnstrd
readch
readchr
readstr
delay
mem_alloc      
mem_free    
file_new
file_open
file_read
file_write
file_close
file_size
exit    
exitp      
newline
halt    
prnstreg    
prnreg        
prnregd
prnregdu    
dumpreg
dumpregd    
dumpregdu      
dumpseg
dumpenv
flags      
stackview      
memview
memviewc
mem_reset
mem_set
mem_copy    
mem_load
opsize
opcode        
prnint        
prnintu
prnhex        
prnhexu
prnoct        
prnoctu
prnbin        
prnbinu
prnbinf
prnbinb
fpbin      
fpbind        
prndbl        
prndble
prndblr
prnflt        
prnfltr
prndblx
dblsplit    
fpdinfo
fpfinfo
dec2str
dec2stru    
hex2str
hex2stru    
dbl2str
readint
readflt
readdbl
fpu_stack      
fpu_sflag      
fpu_cflag      
fpu_tag
fpu_reg
fpu_copy    
fpu_precision      
fpu_round      
sse_round      
sse_flags      
prnxmm        
dumpxmm
clearxmm
prnymm        
dumpymm
clearymm    
prnintd
prnintw
prnintb
str2int
str2dbl
str2flt
dbl2int
int2dbl
rndigit
rndint        
isint      
digiti
digith
factorial
powint        
pow2    
iseven        
isodd      
bconv      
bitfield    
addf    
subf    
mulf    
divf    
pow
sqroot        
log10      
ln10    
deg2rad
rad2deg
sine    
tangent
cosine        
sincos        
atangent    
chr_isdigit
chr_isalpha
chr_isupper
chr_islower
chr_toupper
chr_tolower
chr_chcase        
chr_find    
chr_count      
chr_shuffle
ascii      
str_copy    
str_length        
str_cmpz    
str_cmp
str_toupper
str_tolower
str_reverse
str_trim    
str_wordcnt
str_token      
str_find    
str_findz
str_appendz
str_append
sort_byte
sort_int    
sort_dbl    
sort_dblx      
sort_flt    
aprndbl
aprndblx    
aprnflt
aprnint

So I have been trying to learn the basics of nasm programing. I started by using http://forum.nasm.us/index.php?topic=2062.0 as a base. I am trying to capture text from the user and put it into memory. I just can't seem to figure out how to mov it.

I'm not really familiar with his codebase, but a quick look at his source for nsm64.asm gives a good hint as to what your problem is.

Code: [Select]
;-------------------------------
;readstr(1)/1
;Get string from keyboard
;and 0-ended it
;-------------------------------
;RAX : Address of the buffer
;-------------------------------
;Ret : # of bytes entered in RAX
; : String in buffer
;Note : Use with prnstrz
; : Buffer is of type DB/RB
; : Buffer must be large enough
; : Ret -1 signals error
;-------------------------------

So what this function does is takes as an argument (in RAX) the address of your memory location, the memory location gets updated with the string that was entered by the user, and then RAX is updated with the number of bytes read from the user. So in your code, it should look something like this:

Code: [Select]
...
mov rax, prompt1
call prnstrz
mov rax, name
call readstr
call newline
mov rax, name
call prnstrz
...

Regards,
Bryant Keller

About Bryant Keller
bkeller@about.me