~ubuntu-branches/ubuntu/quantal/gnusim8085/quantal

« back to all changes in this revision

Viewing changes to doc/examples/sorting.asm

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2011-02-21 00:01:55 UTC
  • mfrom: (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110221000155-8k286v0kurbve3fp
Tags: 1.3.7-1
* New upstream release.
* debian/control
  - Update standards version to 3.9.1.
  - Reduce debhelper version required to 5 as no dh7 features are used.
  - Remove autotools-dev build-dep. Not needed anymore.
* debian/copyright
  - Update as per latest source.
* debian/rules
  - Exclude asm-guide.txt from compression as it is loaded by application.
* debian/source/format
  - Specify 1.0 source format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;Copyright (C) 2010  Kirantej J L <kirantej1920@gmail.com>
 
2
;Distributed under same license as rest of the program i.e. GPL v2 or later.
 
3
;See COPYING file for license text.
 
4
 
 
5
;<Sorting>
 
6
 
 
7
; This program is the famous bubble sorting technique, it compares sucessive elements and then sorts
 
8
; This assumes that data is stored in memory location 50
 
9
; Change the initial value of C-register in line-no 17 for different number of inputs
 
10
; The sorted elements are stored in memory location -50
 
11
 
 
12
jmp start
 
13
 
 
14
;data
 
15
 
 
16
 
 
17
;code
 
18
start:  LXI H,50 ;set up as a momory pointer for the bytes
 
19
        MVI D,00 ;Clear register D to set up a flag
 
20
        MVI C,04 ;Set register C for comparision count
 
21
Check:  MOV A,M  ;Get data byte
 
22
        INX H    ; point to next byte
 
23
        CMP M    ;Compare bytes
 
24
        JC NXTBYT ;if (A) < second byte, do not exchange
 
25
        MOV B,M   ;Get second byte for exchange
 
26
        MOV M,A   ;Store first byte in second location
 
27
        DCX H     ;Point to first location
 
28
        MOV M,B   ;Store second byte in first location
 
29
        INX H     ;Get ready for second comparision
 
30
        MVI D,01  ;Load 1 in D as a remainder for exchange
 
31
NXTBYT: DCR C     ;Decrement comparision count
 
32
        JNZ Check ;If comparision count != 0, go back
 
33
        MOV A,D   ;Get flag bit in A
 
34
        RRC       ; place flag bit D0 in carry
 
35
        JC start  ;If flag is 1. exchange occured
 
36
        
 
37
HLT