Very new to assembly language . Please help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Very new to assembly language . Please help

  1. #1
    Join Date
    Sep 2017
    Posts
    14

    Very new to assembly language . Please help

    What does mov means ?

    Why does this code use mov only ?

    Code:
    section	.text
       global _start	 ;must be declared for linker (gcc)
    	
    _start:	         ;tell linker entry point
       mov	edx,len  ;message length
       mov	ecx,msg  ;message to write
       mov	ebx,1    ;file descriptor (stdout)
       mov	eax,4    ;system call number (sys_write)
       int	0x80     ;call kernel
    	
       mov	edx,9    ;message length
       mov	ecx,s2   ;message to write
       mov	ebx,1    ;file descriptor (stdout)
       mov	eax,4    ;system call number (sys_write)
       int	0x80     ;call kernel
    	
       mov	eax,1    ;system call number (sys_exit)
       int	0x80     ;call kernel
    	
    section	.data
    msg db 'Displaying 9 stars',0xa ;a message
    len equ $ - msg  ;length of message
    s2 times 9 db '*'

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,872

    Re: Very new to assembly language . Please help

    Simply, mov means move the contents of the rhs operand to the lhs operand. So

    Code:
    mov edx, 9
    means move 9 to the contents of the register edx.

    Code:
    int 0x80
    means call into the kernel the interrupt procedure no x80 (128). Each system call has a different requirement and the previous mov instructions initialise the requirements for a particular call. register eax is the call number. The other registers are set as needed. So

    Code:
    mov	edx,len  ;message length
    mov	ecx,msg  ;message to write
    mov	ebx,1    ;file descriptor (stdout)
    mov	eax,4    ;system call number (sys_write)
    int	0x80     ;call kernel
    calls write() which has the definition
    Code:
    ssize_t write(int fd, const void *buf, size_t nbyte);
    so register ebx is set to 1 (which is stdout), ecx is set to the memory address at which the text to write resides, edx is set to the number of bytes, eax is set to 4 which is write() and then int 0x80 processes the request.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.0)

  3. #3
    Join Date
    Sep 2017
    Posts
    14

    Re: Very new to assembly language . Please help

    Thanks a lot
    Last edited by mandhabudhi; September 20th, 2017 at 10:02 AM.

  4. #4
    Join Date
    Aug 2017
    Posts
    36

    Re: Very new to assembly language . Please help

    movl $10,24(%esp)
    means: move a literal decimal-10 long (4-bytes) into a 4-byte memory location that begins at the address pointed to by (the esp register plus decimal 24)--basically it is a local variable.

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,872

    Re: Very new to assembly language . Please help

    Quote Originally Posted by Priya456 View Post
    movl $10,24(%esp)
    means: move a literal decimal-10 long (4-bytes) into a 4-byte memory location that begins at the address pointed to by (the esp register plus decimal 24)--basically it is a local variable.
    For which processor/assembler?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)