leto.net
blogs
chronicles
dukeleto.factor
Math::GSL
dukeleto.pl

Subscribe to aggregated feed of all leto.net blogs
me
code
gitweb
math
pics
travel
writing

View Duke Leto's profile on LinkedIn Ohloh profile for dukeleto
Cached copy of http://www.cuillin.demon.co.uk/nazz/trivia/hw/hw_assembler.html

A Collection of Assembler Hello World Programs


From:Michael J. Edelman
Subject: Hello World in IBM 360 Assembler
Someone asked for assembler...well, in IBM 360 assembler, using available
system subroutines in MTS (Kibo's favorite OS), we have:

HELLO   TITLE 'Hello World in IBM 360 Assembler'
HELLO   CSECT
        ENTER 12, SA=SAVAREA
        CALL SPRINT(' Hello, World!')
        EXIT
SAVAREA DC    18A
        EXIT

From:Jay Maynard
Subject:Assembler IBM Mainframe 370 (corrected)
Rich Greenberg  wrote:
>Assembler (IBM Mainframe 370)
>
>HELLO    CSECT
>         USING *,15
>         SAVE  14,12,12(13)
>         LR    12,15
>         USING HELLO,12
>         DROP  12
                ^^
Should be DROP  15

>         WTO   'Hello world.'
>         XR    15,15
>         RETURN (14,12)
>         END

Otherwise, you generate an addressability error...

From:John Schulien
Subject:IBM 370 assembler using the I/O instructions
**************************************************************
**  HELLO - Program to print "Hello, World" on device 009   **
**************************************************************
HELLO    CSECT
         STM   R14,R12,12(R13)    Save Registers
         LR    R12,R15            Load Base Register
         USING HELLO,R12          Establish Addressability
         SSM   =X'00'             Disable Interrupts
         SPKA  0(0)               Disable storage protection
         LA    R2,CCWS            Store pointer to CCW chain
         ST    R2,CAW             ... in Channel Address Word
         LA    R2,9               Put device address in R2
CLEARIO  TIO   0(R2)              Test for device busy
         BC    CC1+CC2,CLEARIO    Wait until device not busy
         BC    CC3,IOERROR        Abort if device error
STARTIO  SIO   0(R2)              Start I/O to the console
         BC    CC1,CSWSTORE       A CSW Has been stored
         BC    CC2,CLEARIO        Device busy. Wait until clear
         BC    CC3,IOERROR        Abort if device error
TESTIO   TIO   0(R2)              Wait for I/O completion
         BC    CC2,TESTIO         Busy, Wait for completion
         BC    CC3,IOERROR        Abort if device error
CSWSTORE CLI   CSW+4,CE           Channel End w/o Device End?
         BE    TESTIO             Yes - wait for Device End too
         TM    CSW+4,BY           Channel Busy?
         BO    TESTIO             Yes - Keep Waiting
         TM    CSW+4,DE           Device End?
         BNO   IOERROR            No - The CSW is bad
SUCCESS  SSM   =X'FF'             Reenable Interrupts
         LM    R14,R12,12(R13)    Restore Caller's Registers
         XR    R15,R15            Clear Return Code
         BR    R14                Return to Caller
IOERROR  SSM   =X'FF'             Reenable Interrupts
         LM    R14,R12,12(R13)    Restore Caller's Registers
         LA    R15,4              Set Return Code 4
         BR    R14                Return to Caller
         DS    0D                 CCW must be doubleword aligned
CCWS     CCW   X'09',MESSAGE,X'20',L'MESSAGE
MESSAGE  DC    C'Hello, World'
CSW      EQU   X'40'         Address of Channel Status Word
BY       EQU   X'10'         Channel Busy
CE       EQU   X'08'         Channel End
DE       EQU   X'04'         Device End
CAW      EQU   X'48'         Address of Channel Address Word
R2       EQU   2             Register 2
R12      EQU   12            Register 12
R13      EQU   13            Register 13
R14      EQU   14            Register 14
R15      EQU   15            Register 15
CC0      EQU   8             Condition Code 0
CC1      EQU   4             Condition Code 1
CC2      EQU   2             Condition Code 2
CC3      EQU   1             Condition Code 3
         END

From:Paul Guertin
Subject:Apple II Assembler
        LDX #12
LOOP    LDA MSG,X
        JSR COUT1       ;APPLE II ROM ROUTINE
        DEX
        BPL LOOP
        RTS
MSG     ASC "!DLROW ,OLLEH"

From:Mr Andrew John Kale
Subject:BBC Micro Assembler
6502 assembler (on BBC Micro, BASIC II)

        ldx #0
.loop   lda msg,x
        beq end
        jsr &ffee
        inx
        bne loop
.end    rts
.msg    equs "Hello, world!"
        equb 0

while those people with BASIC I used to use:

]
$P%="Hello, world!"
P%=P%+LEN("Hello, world!")
?P%=0
P%=P%+1
[

From:Mr Andrew John Kale
Subject:Atari 680x0 Assember
        move.l msg,-(sp)
        move.w #9,-(sp)
        trap   #1
        add.q  #6, sp
        move.w #0,-(sp)
        trap   #1

msg     dc.b "Hello, world!"

From:Eric J. Korpela
Subject:Apple 6502 Cross Assembler
#DEFINE MOS6502
#DEFINE APPLE2
#INCLUDE XASM.MAC
        ORG     $0300
        LDY     #0
LOOP    LDA     STR,Y
        BEQ     DONE
        ORA     #$80            ;CHANGE STANDARD ASCII TO SCREEN CODES
        JSR     COUT            ;$FDED
        INY
        BPL     LOOP
DONE    JMP     $3D0            ;RETURN TO APPLESOFT (BRK HURTS, RTS CAN KILL)
STR     .BYTE   $0D
        .TEXT   "HELLO, WORLD!"
        .BYTE   $0D,$0
        END

From:David Thomas Richard Given
Subject:ARM
.start          STMFD (sp!), {R0-R12, lr}
                ADR R0, message
                SWI OS_Write0
                LDMFD (sp!), {R0-R12, pc}
.message        EQUS "Hello, world!"
                EQUB 0

I think. I may have got the SWI name wrong.

From:Simon Callan
Subject:ARM
        AREA    |ASM$$Code|, CODE, READONLY

        SWI     XOS_WriteI
        =       "Hello world", 10, 13, 0
        ALIGN
        SWI     XOS_Exit
        END

From:Samir Mahendra
Subject:Sun4 Assembler
Use "cc" to compile:

.global _main
_main: save %sp,-16,%sp
.seg "data1"
S: .asciz "Hello World!\012"
.seg "text"
set S,%o0
call _printf,1
nop
ret
restore %o0,0,%o0

From:Mark Robinson
Subject:BBC Micro
I don't have my BBC micro manuals handy, and it's been a lo-o-oo-oooong
time, but

1000 $&2100 = "!dlrow olleH"
1010 FOR N%=0TO2STEP2:P% = &2000:[OPT N%
1020 LDY 11
1030 CLC
1040 .LOOP
1050 LDA &2100,Y
1060 JSR &FFF4 ;   OSWRCH I think, it may be &FFEE
1070 DEY
1080 BCC LOOP
1090 LDA 13
1100 JSR &FFF4 ;   ditto
1110 ]:NEXT
1120 CALL &2000

With these corrections from David Thomas Richard Given
1001 oswrch = &FFEE
1060 JSR oswrch

From:Sven Oliver Moll
Subject:C65 Assembler
$C000 LDX #$00
$C002 LDA $C00E,X
$C005 BEQ $C00D
$C007 JSR $FFD2
$C00A INX
$C00B BNE $C002
$C00D RTS
$C00E .BYTE $48 $45 $4C $4C $4F $20 $57 $4F $52 $4C $44 $21

From:Dave Brown
Subject:A follow up to the C64 code
You forgot to null-terminate your string.  Oops.  Who knows what would
happen then...you can start life on new planets by printing random
PETSCII...and what happened to the comma? (You'd also do well by
putting a newline in there at the end, and not depending on the one
just before the READY. prompt).

From:Richard N. Turner
Subject:80x86 assembly and DOS
cseg        segment    para  public  'code'
            org        100h
            assume cs:cseg,ds:cseg,es:cseg,ss:cseg
hello       proc       near
            mov        dx,offset txt
            mov        ah,9
            int        21h
            mov        ax,4c00h
            int        21h
hello       endp
txt         db         0Dh,0Ah,'Hello, World!',0Dh,0Ah,'$'
cseg        ends
            end        hello

From:Eric Korpela
Subject:8080 and DOS
;----------------------------------------------------------------------
        ORG     0100H           ; Where we start
        MVI     C,09H           ; Print string function
        LXI     D,MESSAGE       ; Point
        CALL    0005H           ; Call bdos
        RET                     ; To cp/m  (Is it really this simple?)
MESSAGE:DB      0DH,0AH,'Hello, World!.,ODH,OAH,'$'
        END
;----------------------------------------------------------------------

From:Eric Korpela
Subject:68020 assembly for gcc
.text
Hello:
        .ascii "Hello, World!\12\0"
        .even
.globl _main
_main:
        link a6,#0
        pea Hello
        jbsr _printf
        unlk a6
        rts

From:Hans Guijt
Subject:Z80 for an MSX machine
        LD A, 13
        LD HL, WString
        CALL TxtOut
        RET

WString DC.B "Hello, world!"

(registers may be wrong, as well as the name of the BIOS call - it's been ages)

From:Sean 'Captain Napalm' Conner
Subject:80x86 for MS-DOS
;----------------------------------------------
; 80x86 for MS-DOS:
;----------------------------------------------

code            segment para
                assume  cs:code,ds:code

                org     0100h
start:          mov     dx,offset message       ;point to message
                mov     ah,09h                  ;MS-DOS function # to print string
                int     21h                     ;call DOS
                mov     ax,4c00h                ;exit
                int     21h

message         db      'Hello World!',13,10,'$'
                end     start

From:Sean 'Captain Napalm' Conner
Subject:68K for Amiga (AmigaDOS 1.3)
;---------------------------------------------
; 68K for Amiga (AmigaDOS 1.3)
;----------------------------------------------
                include "exec/types.i"
                include "exec/funcdef.i"
                include "exec/exec.i"
                include "libraries/dos_lib.i"
                include "libraries/dos.i"

                segment _code,code
start           move.l  #dos.library,a1         ;open the dos library
                moveq   #0,d0
                move.l  4,a6
                jsr     _LVOOpenLibrary(a6)
                move.l  d0,a6
                tst.l   d0                      ;if result is NULL,
                beq.w   exit                    ;then exit
                jsr     _LVOOutput(a6)          ;get stdout
                move.l  d0,d1                   ;call Write(stdout,buff,size)
                move.l  #message,d2
                moveq   #12,d3
                jsr     _LVOWrite(a6)
                move.l  a6,a1                   ;close library
                move.l  4,a6
                jsr     _LVOCloseLibrary(a6)
exit            rts                             ;exit

                segment _data,data
message         dc.b    'Hello world!',10
                end     start

From:Sean 'Captain Napalm' Conner
Subject:MIPS R3000 running IRIX 4.0.1
;-------------------------------------------------------
; MIPS R3000 running IRIX 4.0.1
;-------------------------------------------------------

                .set    noreorder

                .text
main:           lui     r5,high helloworld      ;load address of message
                addui   r4,r0,$0001             ;stdout
                addui   r5,r0,low helloworld    ;load address of message
                addui   r6,r0,12                ;size
                addui   r2,r0,1004              ;the write system call
                syscall
                sll     r0,r0,0                 ;nop
                addui   r2,r0,1001              ;exit system call
                syscall
                sll     r0,r0,0                 ;nop
helloworld:     .ascii  "hello world\n"

From:Sean 'Captain Napalm' Conner
Subject:Color Computer with 6809
;-----------------------------------------------------
; Color Computer with 6809
;-------------------------------------------------------

START   LDX     #MESG   POINT TO MESSAGE
        BSR     PRINT   PRINT MESSAGE
        RTS

PRN10   JSR     [$A002] PRINT CHARACTER IN A
PRINT   LDA     ,X+     GET NEXT CHARACTER
        BNE     PRN10   IF NOT 0, PRINT IT
        RTS

MESG    FCC     'HELLO WORLD!'
        FCB     0

From:Joerg Pommnitz
Subject:Linux on x86
.text
.globl _start
_start:
movl    $1,%ebx         / file descriptor for stdout in EBX
movl    $hello,%ecx     / address of buffer in ECX
movl    $13,%edx        / length in EDX
movl    $4,%eax         / syscall number for write is 4
int     $0x80           / syscall
movl    $0,%ebx         / exit code is 0
movl    $1,%eax         / syscall number for exit is 1
int     $0x80           / syscall
.data
hello:
.ascii  "Hello world!\n"


From:nickz
Notes:
BTW, here's the meanings of some of the mnemonics:  .mcall means use a
system macro library to generate a system call that typically uses an EMT
(emulator trap) instruction).  .asciz is an ASCII string terminated by a
zero byte, .even means pad with a zero byte if needed so the next
instruction starts on an even word boundary.  # means use immediate
addressing, which stores the operand in the next word.  <15><12> are the
octal codes for carriage return and linefeed (hex 0D, 0A). QIOW$S means
Queue I/O Request and Wait, with arguments pushed on the Stack.  io.wvb
means Write Virtual Block, and lsb means Local Statement Block (so local
labels can be unique within each particular block.  For older assemblers,
.enabl lc, lsb is a good idea so that the listing does not convert
lowercase to uppercase - unless you list it on a really ancient
uppercase-only terminal.  Under RT-11, this is only a concern before
Version 5.0 (c. 1983).

Of course, everything following a semicolon (;) is a comment and is
ignored by the assembler.

BTW, these operating systems are still in use, and a Y2K update (V5.7 for
RT-11 and 5 something? for RSX) is scheduled to be released soon by their
current owner, Mentec, which acquired them from the original owner, DEC,
well before the recent merger with Compaq.  Many users have already made
the changes themselves, however, since source code is usually supplied
with the distributions.

Those without a real PDP-11 or Pro 300 series personal computer can run
PDP-11 code on a PC using an emulator like E11 or Bob Supnik's emulator;
the latter will compile on any Unix system also, but the former is faster.
There are older versions of the operating systems available for free on
the net, for those who can't or won't buy a newer version.
From:nickz
Subject:PDP-11 Macro-11 under RT-11
        .mcall  .print, .exit
hello:  .asciz  <15><12>/Hello, world!/
        .even
start:  .print  #hello
        .exit
        .end    start

From:nickz
Subject:PDP-11 Macro-11 under RSX or P/OS

        .mcall  qiow$s, exit$s
hello:  .ascii  <15><12>/Hello, world!/
        hellol=.-hello
iostat: .blkw   2
        .even
start:  qiow$s  #io.wvb,#5,#2,,#iostat,,<#hello,#hellol,#40>
        exit$s
        .end    start

From:nickz
Subject:PDP-11 Bootblock version, no operating system needed

;       By Nicholas Zymaris, 13-Nov-1997, text changed to Hello World on
;       9-Jul-1998 (nickz@idt.net).

;       Standard all-purpose non-bootable PDP-11 bootblock for RT-11 or other
;       operating systems (used on DX, DY, DL, DZ, etc.), like the one
;       that says "No boot on volume".

;       The initial jumps are strictly unnecessary but are included for
;       compatibility with the usual bootblocks.  Can be copied to the boot
;       sector of a diskette or other device via SIPP under RT-11 or a disk
;       editor under RSX or P/OS; ask if you need utilities.

;       Instead of booting an operating system, it will print the message
;       and sit there, as with a standard non-system diskette.  Could add
;       code to load an OS afterwards, but then it would not be a simple
;       Hello World program...

;       Link it /NOBITMAP so extraneous 200 not put in word at loc. 360

        .asect
        .=0
        .globl  stack
        stack=776               ; probably a good value for it
        ttcsr=177564            ; for console I/O
        ttdat=177566
        .enabl  lsb
start:  nop                     ; Not strictly necessary; for compatibility
        reset                   ; with other bootblocks
        br      1$              ; Bypass device & filesystem information
        .word   0,0,41420,116020 ; actual values in this line not critical
1$:     br      .+2             ; (.word 400) This is location 16
        jsr     r0,2$           ; Call the inline display routine
        .word   15,0,5000       ; , etc.
        .asciz  /Hello, world! /<15><12><12><200>       ; 200 for BPL
                                ; The above string must have an even
                                ; length; if odd, pad with a space, etc.
                                ; before, not after the <200>, not with .even

2$:     tstb    @#ttcsr         ; Is terminal ready to receive a character?
        bpl     2$              ; Not yet, try again
        movb    (r0)+,@#ttdat   ; Send it another character
        bpl     2$              ; And go back for more
        br      .               ; Done, sit there and wait for reboot.
        .dsabl  lsb
        .end    start

;Sincerely, Nicholas Zymaris (I wrote all these programs, so there's no
;copyright problem).


From:Orsila Heikki
Subject: 68K for Amiga OS
I've got another one. It's actually a fix for assembler
version of amiga-os prog.. It had some flaws like inappropriate
error handling and strange assembler syntaxes not generally
used :)

;---------------------------------------------
; 68K for Amiga OS
;----------------------------------------------
                include "exec/types.i"
                include "exec/funcdef.i"
                include "exec/exec.i"
                include "libraries/dos_lib.i"
                include "libraries/dos.i"

                section code,code
start
                lea     dosname,a1
                moveq   #0,d0
                move.l  4,a6
                jsr     _LVOOpenLibrary(a6)
                move.l  d0,a6
                tst.l   d0
                beq     error
                jsr     _LVOOutput(a6)
                move.l  d0,d1
                move.l  #Message,d2
                moveq   #MessageEnd-Message,d3
                jsr     _LVOWrite(a6)
                move.l  a6,a1
                move.l  4,a6
                jsr     _LVOCloseLibrary(a6)
                moveq   #0,d0
                rts
error           moveq   #-1,d0
                rts

                section  data,data
dosname         dc.b    'dos.library',0
Message         dc.b    'Hello world!',10,0
MessageEnd

From:Steven Inness
Subject:Linux on Intel 80x86 using nasm (Intel syntax)
;"Hello World" for Linux on Intel 80x86 using nasm (Intel syntax).
;Enter this into "hello.asm" then type:
;"nasm -f elf hello.asm"
;"ld hello.o -o hello"
;"./hello"

section .data                   ;data section declaration
msg     db      'Hello World!',0AH
len     equ     $-msg           ;string length

section .text                   ;code section declaration
global  _start                  ;entry point (start of execution)
_start: mov     edx,len         ;string length
        mov     ecx,msg         ;string start
        mov     ebx,1           ;file handle: stdout
        mov     eax,4           ;sys_write
        int     80h             ;kernel system call

        mov     ebx,0           ;return value
        mov     eax,1           ;sys_exit
        int     80h             ;kernel system call


From:Steven Inness
Subject:OpenBSD on Intel 80x86 using as (AT&T syntax)
#"Hello World" for OpenBSD on Intel 80x86 using as (AT&T syntax).
#This file should have only LF's (\n), not CRLF's.
#Enter this into "hello.asm" then type:
#"as hello.asm -o hello.o"
#"ld hello.o -o hello"
#"./hello"

        .data                   #data section declaration
msg:    .ascii  "Hello, World!\n"
        len = . - msg           #string length

        .text                   #code section declaration
        .global _start          #entry point (start of execution)
_start: pushl   $len            #string length
        pushl   $msg            #string start
        pushl   $1              #file handle: stdout
        movl    $4,%eax         #sys_write
        call    sys_call
        addl    $12,%esp        #clean up stack

        pushl   $0              #return value
        movl    $1,%eax         #sys_exit
        call    sys_call

sys_call:
        int     $0x80           #kernel system call
        ret
#Make sure there is no DOS ^Z EOF mark here


From:Anastasija
Subject:"Hello, World !" in Asm :)
This is one of my first program in asm :)

        .MODEL SMALL
        .STACK 100h
        .DATA
Message db 'Hello, World !',13,10,'$'
Green           db 13,10,'Green Peace: Save our planet ! ;)',13,10,'$'
        .CODE
Start:
        mov     ax,@Data
        mov     ds,ax
        mov     ah,9
        lea     dx,Message
        int     21h

        mov     si,dx
        add     si,0bh
        mov     cx,05h
        mov     bl,23h

LoopRep:
        mov     [si],bl
        dec     si
        dec     cx
        int     21h
        jnz     LoopRep

        lea     dx,Green
        int     21h

        mov     ah,4ch
        int     21h
        END     Start

From:Silencio
Subject:Hello, World!
The Hello, World program in x86 Assembler on MS-DOS (TurboAssembler):

DATA SEGMENT

      Hello DB "Hello, World!"
            DB "$"

DATA ENDS

CODE SEGMENT

     ASSUME     CS:CODE, DS:DATA

     Hello_World:
        MOV     AX, DATEN
        MOV     DS, AX
        MOV     DX, OFFSET Hello
        MOV     AH, 9
        INT     21h
        MOV     AH, 4Ch
        INT     21h

CODE ENDS

END Hello_World


Jonathan Leto - jonathan at leto dot net
sp-sticker.gif

Generated Friday 24th of October 2014 06:51:42 PM
Clicky Web Analytics

Clicky