Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 31

Thread: "Hello world" in assembler

  1. #11

    Re: "Hello world" in assembler


    sure - how about moving "Hello World" out through the UART.
    That's the same as the serial port, right? You just have to open /dev/ttyS0 (or whichever port you want) and write the string to the file just as I wrote it to stdout in this example. Or were you meaning something else?

  2. #12

    Re: "Hello world" in assembler

    yea! that would be the serial port. I did not know you could do systems calls in assembler - how cool! freaking rtxc RTOS there are no system calls while in assembler. i hate rtxc...

  3. #13

    Re: "Hello world" in assembler


    I don't know, maybe I am just a dumb goof, but that looks incredibly hard for such a simple proggy. I need to learn assembly, but it is such a different way of thinking than I am used to...from the looks of it it is obviously going to take a lot of time...

    Aragorn
    It may help to know about registers. They're small memory cells in the processor ranging from 8 to 32 bit (and up to 80 bit in the floating point processor, there's probably a C identifier for 80 bit floating point numbers). Most of the smaller registers are a part of larger registers. For instance, ax is a 16 bit register. It's divided into two 8 bit registers: ah on the high side (most significant bits) and al on the low side. And ax is the low half of the 32 bit register eax. Are you following me? So if you did

    mov eax,012345678h # you always have to precede hex numbers with 0 in Nasm
    then ax would be 5678h, ah would be 56h, and al would be 78h. Hopefully you understand that. Another thing you need to know is that you almost always have to have data in registers to manipulate it or store it somewhere. You can store values directly into memory and increment or decrement memory addresses, and transfer a memory address directly to a device, but those are about it. You must have values in registers to do math on them. Now I'll list the main registers with their functions. Note that although they have specific purposes, most of them can be used for ordinary stuff, like arithmetic operations.

    32-bit:
    Here are the main data registers. They're more commonly used for normal data manipulation than the others.

    eax - Accumulator: always used as destination for some math operations.
    ebx - Base register: used for some memory and port operations.
    ecx - Count register: used for loops.
    edx - Data register: no specific function that I can think of.

    These are the pointers. The first one on each line is a segment register. It points to a large chunk of memory where something is. It's actually 16-bit but is used with the 32-bit processors as well as the 16-bit ones. The second one is a pointer register. It points to the specific spot. Segment registers cannot be altered directly or used in math operations. They are not very useful in 32 bit mode either.

    ds:esi - source index pointer: specifies source address when moving strings.
    es:edi - destination index pointer: take a guess.
    ss:ebp - stack base pointer: points to the base of the stack.
    ss:esp - stack pointer: points to the top of the stack.
    cs:eip - program counter: points to the memory location where program is executing.

    eflags - special register that holds boolean flags for certain conditions.

    16-bit:
    For the most part, the same as the 32-bit registers minus the first e in the name.

    8-bit:
    Ax, bx, cx, and dx are all divided into 8-bit registers. They all have h or l in place of the x depending on they're on the high side or low side. None of the other before-mentioned registers are divided like this.

    That's it for the registers. I should make a tutorial on assembler. Here's a little program that finds the factorial of a number. It has no user interaction though, not even printing the results onto the screen. It doesn't even exit. It's more like a piece of a program.

    Code:
    SEGMENT .data
    factor dd 0100h
    
    SEGMENT .text
    mov eax,01h # start eax as 1
    mov ecx,[factor] # move contents of factor to ecx
    repz mul ecx # multiply ecx by eax (eax is always an operand and the destination of mul) until ecx = 0

  4. #14

    Re: "Hello world" in assembler


    yea! that would be the serial port. I did not know you could do systems calls in assembler - how cool! freaking rtxc RTOS there are no system calls while in assembler. i hate rtxc...
    I have no idea what rtxc or RTOS are. But for the record, assembler is equivelant to machine code. Anything you can possible program on a computer can be done in assembler. Furthermore, you may not realize this, but the header files for C and C++ are written in assembler. Some of them may not but they also #include some other file and when you go down the chain, you eventually get to assembler. You can't do any user interaction in C or C++ without including header files that have assembler in them. All you can do is define variables and manipulate them. I bet that if you grabbed header files from a Windows compiler and included them when compiling in gcc, you could create a .o file that could be linked in Windows to create a Windows executable. I would try it if I had Windows header files (and Windows for that matter). But for the record, the int command (interrupt) is used to make system calls.

  5. #15

    Re: "Hello world" in assembler

    rtxc is a real time OS (RTOS). assembly is needed quite frequently because the rtxc will go off in la la land unless things are executed in a certian way. obviously the kernel is written in assmebly, but many other calls which one may not expect are also written in assembly, to get any accurate delay loop it needs to be done in assbembly because of the overhead of the compiler and the pooky processor it is on. (mcore clocked at 16.8 MHz) .

  6. #16
    Guest

    Re: "Hello world" in assembler

    I would write a 68HC11 program for this, but I realized that I don't know how to output a string to standard output without having to use C.

    Otherwise, I could it by outputting it on the 68HC11 board, but that would be no challenge...

  7. #17
    Guest

    Re: "Hello world" in assembler

    Code:
    #!/usr/bin/env ruby
    
    puts "Hello World!"
    Why make it complicated when you can keep it simple!

  8. #18
    Guest

    Re: "Hello world" in assembler

    Assembly is fun, because you learn about the hardware at the same time and writing assembly code is much more efficient than having it generated by a compiler.

    It's all about efficiency and time-critical apps, nobody really wants to code in assembly...unless they love (I do, but not enough to sacrifice time).

  9. #19
    Guest

    Re: "Hello world" in assembler


    Assembly is fun, because you learn about the hardware at the same time and writing assembly code is much more efficient than having it generated by a compiler.

    It's all about efficiency and time-critical apps, nobody really wants to code in assembly...unless they love (I do, but not enough to sacrifice time).
    Depends who you code for. Most companies I know, if you ask them: "What's more important to you: price or efficiency?" will answer price. Since the time that costs the most is programmer time, assembly is losing popularity while languages where you can develop really fast (like Ruby and Python) are getting more and more popular. Plus, CPU's are faster and faster.

  10. #20

    Re: "Hello world" in assembler

    size and space are very important. my boss would freak if i said 'lets do this in <insert interpertated language here>" . although in most cases C is the best thing to use. the compiled code is small and fast. i would like to see how "hello world" does in assembly as well as c in size and speed....

Similar Threads

  1. "Historic" Open Source Victory - GPL is legally valid and enforcable!
    By beezlebubsbum in forum Linux - General Topics
    Replies: 0
    Last Post: 02-22-2010, 11:33 PM
  2. "MicroHat" "SoftRed"
    By Fatal Error in forum General Chat
    Replies: 0
    Last Post: 05-12-2005, 09:03 PM
  3. "groupadd" and "tree" utilities are nowhere??
    By aromes in forum Redhat / Fedora
    Replies: 1
    Last Post: 10-05-2003, 03:50 AM
  4. error installing packages "krb5-libs" ; AND NVIDIA troubles
    By SaTaNcLaUz in forum Linux - General Topics
    Replies: 23
    Last Post: 11-14-2002, 09:26 PM
  5. Xlib:  extension "GLX" missing on display ":0.0".
    By ph34r in forum Linux - Software, Applications & Programming
    Replies: 5
    Last Post: 12-06-2001, 04:52 PM

Bookmarks

Posting Permissions

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