linux - Assembly: writing multiple lines into a buffer -


i have problem second ever program in assembly. task read multiple lines of text keyboard , write them down buffer (.comm). after empty line entered, program should echo in loop each typed line of text. limit 1 line of text 100 charcters. however, "program received signal sigsegv segmentation fault / 0x00000000006000a5 in check ()" error message.

my idea create buffer of size 5050 bytes. each line of text can have @ 100 characters. here visual structure of buffer:

[first line     ][0][second line      ][0][short            ][0][text             ][0] 

update: according jester's reply (thanks!), i've modified idea program. abandoned idea of 100 bytes per line. i'll place them 1 after another, separating them special character (0). new structure of buffer be:

[first line of text][0][no matter how long is][0][short][0] 

however, i've got problem appending special "0" character buffer in "add_separator" part. wonder if it's necessary since add "\n" new line indicator buffer asswell?

also, part when check if entered line of code empty never returns true (empty line state) program keeps loading , loading new lines. did miss anything?

here updated bit of code:

sysexit = 1 sysread = 3 syswrite = 4 stdout = 1 stdin = 0 exit_success = 0  .align 32  .data #data section      .comm buffer, 5050  #my buffer of size of 5050 bytes     buffer_len = 5050   .global _start  _start:  mov $0,%esi  read:      mov $sysread, %eax     mov $stdin, %ebx     mov buffer(%esi), %ecx     mov $1, %edx     int $0x80     check:      cmp $0, %eax        # check if entered line empty     je end          # if yes, end program      lea buffer(%esi), %ecx  # move latest character comparison     cmp '\n', %ecx      # check if it's line end      inc %esi        # increment iterator     je end     jmp read  end:      mov $syswrite, %eax     mov $stdout, %ebx     mov $buffer, %ecx     mov $buffer_len, %edx      int $0x80      mov $sysexit, %eax     mov $exit_success, %ebx     int $0x80 

thanks in advance tips!

filip

a few things:

  1. trust me, don't want use esp general purpose register beginner
  2. the read system call read @ many bytes specify (in case buffer_len) , return number of bytes read. should pass in 1 instead, can read char-by-char.
  3. adding 100 next word (you mean line, right?) isn't terribly useful, append each character continuously since that's how want print them too.
  4. cmp '\n', %al try use '\n' address, want cmp $'\n', %al use immediate
  5. learn use debugger find own mistakes
  6. using jg jump on jle unnecessary, keep jle , let execution continue otherwise

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -