Sponsored Content
Full Discussion: Understanding Assembly Code
Top Forums Programming Understanding Assembly Code Post 302931995 by Azrael on Sunday 18th of January 2015 01:04:54 AM
Old 01-18-2015
Understanding Assembly Code

As the title suggests, I want to better understand the following assembly code:

Code:
section .text
    global main          ; must be declared for linker (gcc)
main:                        ; tell linker entry point
    mov    edx, len     ; message length
    mov    ecx, msg    ; message to write
    mov    ebx, 1         ; file descriptor (stdout)
    mov    eax, 4         ; syscall for write (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        ; syscall number for write (sys_write)
    int      0x80          ; call kernel
    mov    eax, 1        ; system call (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 '*'

As you can see I already have descriptions in the comments from the tutorial I found here. Here are some of the things I don't understand:

1. - What is s2? Is this just a variable or a register I know nothing about?

2. When '1' is moved into ebx, is this a parameter to the sys_exit later called in eax? I found a listing of Linux syscalls here and it does seem sys_exit does take one parameter in ebx that's an integer. If this is the case why not exit cleanly with zero?

I just want to make sure I understand everything correctly in this. Thanks in advance!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Understanding Code in IF LOOP

Hello All, I would like to know and understand the difference between the below 3 IF loops and also if possible what are the different other parameters i could use other than those mentioed in the below lF LOOP conditions, appreciate your help. Thanks, Sam. (1 Reply)
Discussion started by: Ariean
1 Replies

2. UNIX Desktop Questions & Answers

Understanding the code

hello all, May i know what is this "DEBUG_ME $DEBUG_CMD main" doing in the below code. I am confused with alias also "alias DEBUG_ME='#'". Thanks for your help. set -x alias DEBUG_ME='#' if ; then . /product/apps/informatica/v7/pc/ExtProc/debug.ksh "$1" fi # Declaring the... (1 Reply)
Discussion started by: Ariean
1 Replies

3. Programming

Need assembly code for C program

Dear Buddies, I need assembly code for a compiled c program in unix. Kindly help me.... Thanking you in advance. (1 Reply)
Discussion started by: karthik537
1 Replies

4. Programming

Help with assembly code

I want make simple assembly code for some thing like this a^6+6a^2+2a and range of a is between -3 to 3. I tried but it is not working properly. As this is my first assembly program that I am going to try, I want some help with it. I found this example online but i dont want this kind of... (2 Replies)
Discussion started by: Learnerabc
2 Replies

5. Shell Programming and Scripting

Help understanding Perl code.

Well, I found myself trying to fix some Perl code (Ive never done any Perl in my life) and I pinpointed the place where the bug could be. But to be sure I have to know what does a few line of code mean: $files_lim =~ (/^\d*$/) $files_lim =~ (/^\d*h$/)$files_age =~ s/h//The code where this was... (0 Replies)
Discussion started by: RedSpyder
0 Replies

6. Shell Programming and Scripting

Help understanding some Perl code.

Well, I found myself trying to fix some Perl code (Ive never done any Perl in my life) and I pinpointed the place where the bug could be. But to be sure I have to know what does a few line of code mean: $files_lim =~ (/^\d*$/) $files_lim =~ (/^\d*h$/) $files_age =~ s/h// The code where... (2 Replies)
Discussion started by: RedSpyder
2 Replies

7. Programming

Understanding perl code

What is the difference between the two statements below? A: $a->{"$fruit"}->{"$color"}->{size} = $size B: $size = $a->{"$fruit"}->{"$color"}->{size} Please assist. Thanks! (0 Replies)
Discussion started by: onlinelearner02
0 Replies

8. Shell Programming and Scripting

auto-generating assembly code by variables found by script

Hi everybody I'm working on a list of registers(flip-flops to be exact), now i need to extract some value from this list and use them as arguments to pass them to some assembly code for example i have: 118 chain79 MASTER (FF-LE) FFFF 1975829 /TCK F FD1TQHVTT1 ... (1 Reply)
Discussion started by: Behrouzx77
1 Replies

9. Shell Programming and Scripting

Help with perl code understanding

Hi, I need to understand below perl code, can some one advise me. perl -MDate::Parse -e'BEGIN{$main::now=time;$main::old=(time-60*30)}' -nE'if(/^(\w+\s+\d+\s+\d+:\d+:\d+)/) {$t=str2time $1; $t > $old && $t < $now && print}' (1 Reply)
Discussion started by: learnbash
1 Replies

10. Shell Programming and Scripting

[Solved] Help understanding this code!!

Hi guys, I am still learning awk and much apprecated to shed some light on the following: the questions asked is below! { total = i = 0 do { ++i total += $i } while ( total <= 100 ) print i, ":", total } File used: cat test.do 45 25 60 20 10 105 50 40 33 5 9 67 108 3 5 4 (2 Replies)
Discussion started by: Apollo
2 Replies
BOOT(8) 						      System Manager's Manual							   BOOT(8)

NAME
boot - startup procedures DESCRIPTION
A PDP11/45 and PDP11/70 UNIX system is started by a two-stage process. The first is a primary bootstrap which is able to read in rela- tively small stand-alone programs; the second (called boot) is used to read in the system itself. The primary bootstrap must reside in the otherwise unused block zero of the boot device. It can be read in and started by the standard ROM programs, or if necessary by keying in a small startup routine. This program is capable of loading type 407 executable files (not shared, not separate I&D). The user types on the system console the name of the program wished, in this case boot, followed by a carriage return; the named program is retrieved from the file system that starts at block 0 of drive 0 of the boot device. No prompt is given, no diagnos- tic results if the file cannot be found, and no provision is made for correcting typographical errors. The second step, called boot, actually brings in the system. When read into location 0 and executed, boot sets up memory management, relo- cates itself into high memory, and types a `:' on the console. Then it reads from the console a device specification (see below) followed immediately by a pathname. Boot finds the corresponding file on the given device, loads that file into memory location zero, sets up mem- ory management as required, and calls the program by executing a `trap' instruction. Normal line editing characters can be used. Conventionally, the name of the secondary boot program is `/boot' and the name of the current version of the system is `/unix'. Then, the recipe is: 1) Load block 0 of the boot device by fiddling with the console keys as appropriate for your hardware. If you have no appropriate ROM, some programs suitable for manual use are given below. 2) Type boot. 3) When the prompt is given, type hp(0,0)unix or rp(0,0)unix depending on whether you are loading from an RP04/5/6 or an RP03 respectively. The first 0 indicates the physical unit number; the second indicates the block number of the beginning of the logical file system to be searched. (See below). When the system is running, it types a `#' prompt. After doing any file system checks and setting the date (date(8)) a multi-user system is brought up by typing an EOT (control-d) in response to the `#' prompt. Device specifications. A device specification has the following form: device(unit,offset) where device is the type of the device to be searched, unit is the unit number of the device, and offset is the block offset of the file system on the device. Device is one of the following rp RP03 hp RP04/5/6 rk RK05 For example, the specification hp(1,7000) indicates an RP03 disk, unit 1, and the file system found starting at block 7000 (cylinder 35). ROM programs. The following programs to call the primary bootstrap may be installed in read-only memories or manually keyed into main mem- ory. Each program is position-independent but should be placed well above location 0 so it will not be overwritten. Each reads a block from the beginning of a device into core location zero. The octal words constituting the program are listed on the left. RK (drive 0): 012700 mov $rkda,r0 177412 005040 clr -(r0) / rkda cleared by start 010040 mov r0,-(r0) 012740 mov $5,-(r0) 000005 105710 1: tstb (r0) 002376 bge 1b 005007 clr pc RP (drive 0) 012700 mov $rpmr,r0 176726 005040 clr -(r0) 005040 clr -(r0) 005040 clr -(r0) 010040 mov r0,-(r0) 012740 mov $5,-(r0) 000005 105710 1: tstb (r0) 002376 bge 1b 005007 clr pc FILES
/unix - system code /usr/mdec/rpuboot, /usr/mdec/hpuboot - copies of primary bootstrap /boot - second stage bootstrap SEE ALSO
init(8) BOOT(8)
All times are GMT -4. The time now is 01:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy