Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6812815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:29:43+00:00 2026-05-26T20:29:43+00:00

My program calls function 183 (getcwd) of interrupt 80h which copies an absolute pathname

  • 0

My program calls function 183 (getcwd) of interrupt 80h which copies an absolute pathname of the current working directory to the memory location pointed to by buff, which is of length 4096. Returned absolute pathname length is usually less than 4096 bytes so i want to get its true length. How can i do that?

%define LF 0Ah      ; Line feed ASCII code.
%define STDOUT_FILENO 1 ; Standard output stream.
%define SYS_exit    1
%define SYS_write   4
%define SYS_getcwd  183
SECTION .bss
    buff resb 4096
SECTION .text
    global _start
_start:
    mov eax, SYS_getcwd ; getcwd
    mov ebx, buff
    mov ecx, 4096
    int 80h
    mov eax, SYS_write  ; print result to stdout
    mov ebx, STDOUT_FILENO
    mov ecx, buff
    mov edx, 4096
    int 80h
    mov eax, SYS_exit   ; exit
    mov ebx, 0
    int 80h

I add code to find length of null terminated string to my program as following and it works:

%define LF 0Ah      ; Line feed ASCII code.
%define STDOUT_FILENO 1 ; Standard output stream.
%define SYS_exit    1
%define SYS_write   4
%define SYS_getcwd  183
SECTION .data
    mesg1 db "Can't not find string length.",LF
    mesg1_l db $-mesg1
SECTION .bss
    buff resb 4096
SECTION .text
    global _start
_start:
    mov eax, SYS_getcwd ; getcwd
    mov ebx, buff
    mov ecx, 4096
    int 80h
    mov al, 0       ; find string length with scasb
    mov edi, buff
    cld
    repne scasb
    jne error1
    sub ecx, 4096
    neg ecx
    mov edx,ecx
print:  mov byte [buff + ecx],LF
    mov byte [buff + ecx + 1], 0
    inc edx
    mov eax, SYS_write  ; print result to stdout
    mov ebx, STDOUT_FILENO
    mov ecx, buff
    int 80h
    jmp exit
error1: mov eax, SYS_write
    mov ebx, STDOUT_FILENO
    mov ecx, error1 
    mov edx, mesg1_l
    int 80h
exit:   mov eax, SYS_exit   ; exit
    mov ebx, 0
    int 80h
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:29:44+00:00Added an answer on May 26, 2026 at 8:29 pm

    Q: How do I find the length of a string (e.g. the string returned by “getcwd()”)?

    A: The same way the standard library function “strlen()” would do it: parse the string until you find a ‘\0’ delimiter, then return that position as the string length.

    PS:
    I’d strongly urge you to consider using Gnu Assembler “gas” instead of “nasm”. As soon as you start playing with assemblers other than x86, the “bass-ackwards” Intel syntax gets really annoying.

    IMHO …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program which calls a library function ( http://www.diku.dk/hjemmesider/ansatte/pisinger/3dbpp.c )
I tried to trace ODBC function calls from my program working on Linux. This
I have a C program which has a function call that is defined in
I have a program (NWShader) which hooks into a second program's OpenGL calls (NWN)
I launch my program in C#, which then calls some unmanaged C++. When I
My C program had a lot of strstr function calls. The standard library strstr
Following scenario: In an WPF application the program calls Log.Write to enqueue messages which
I have an AS3 program that calls a function multiple times. The function must
I have been struggling with a program that calls functions which return strings. I
I have a program that constantly calls a function. In my function i use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.