Docker Community Forums

Share and learn in the Docker community.

Register address of Passed in Arguments

I am building an executable that will be an assembly .o file. I have tried numerous tests, but I am unable to determine what registers the base FROM scratch image is using for command line arguments

Here is the full Dockerfile.

#Builder image, usually contains sdk's/build tools that won't be needed during runtime
FROM christopherclark/nasm-builder as builder
#Copy contents from current directory, dockerfile, and main.asm
COPY ./ ./
#Does your building and linking of the file.
RUN nasm -f elf64 main.asm
RUN ld -s -o main main.o
#a single executable called main now exists

#the last image is the image that will be used when you run your container, usually you want this to be as small as possible
FROM scratch
#Copy everything you need, notice the syntax, you can specificy from which stage you want to copy.
COPY --from=builder /main /main
#EXPOSE 60833
ENTRYPOINT ["/main"]

I have tried numerous ways to pass in arguments, directly in the entry point, with

ENTRYPOINT["/main", "hello"]

I have tried with cmd when running my docker image

docker run -ti main-asm heyo!

I have tried numerous registers and echoing them to the console and to no avail. The only thing that worked was actually prompting the user with stdin first. I need to read the arguments at the start of the program. Please advise. Here is the working example that prompts the user.

section .data                           ;Data segment
   userMsg: db 'Please enter a number: ' ;Ask the user to enter a number
   lenUserMsg: equ $-userMsg             ;The length of the message
   dispMsg: db 'You have entered: '
   lenDispMsg: equ $-dispMsg    
   buffer: times 20 db 0
   bufferLen: resb 20           

section .bss           ;Uninitialized data
   num resb 5
	
section .text          ;Code Segment
   global _start
	
_start:   
   ;User prompt
   mov eax, 4
   mov ebx, 1
   mov ecx, userMsg
   mov edx, lenUserMsg
   int 80h

   ; ;Read and store the user input
   mov eax, 3
   mov ebx, 2
   mov ecx, num  
   mov edx, 5          ;5 bytes (numeric, 1 for sign) of that information
   int 80h
	
   ;Output the message 'The entered number is: '
   mov eax, 4
   mov ebx, 1
   mov ecx, dispMsg
   mov edx, lenDispMsg
   int 80h  

   ;Output the number entered
   mov eax, 4
   mov ebx, 1
   mov ecx, num
   mov edx, 5
   int 80h 

   ; Exit code
   mov eax, 1
   mov ebx, 0
   int 80h