Use backtick code blocks for syntax highlighting
This commit is contained in:
parent
8ed9dea394
commit
f658bfbb40
203 changed files with 26546 additions and 25801 deletions
57
09-05.md
57
09-05.md
|
|
@ -43,38 +43,39 @@ one.
|
|||
|
||||
**LISTING 9.4 L9-4.ASM**
|
||||
|
||||
.
|
||||
;--------------------------------------------------------------------------
|
||||
; Sorts an array of ints. C callable (small model). 25 bytes.
|
||||
; void sort( int num, int a[] );
|
||||
;
|
||||
; Courtesy of David Stafford.
|
||||
;--------------------------------------------------------------------------
|
||||
```nasm
|
||||
;--------------------------------------------------------------------------
|
||||
; Sorts an array of ints. C callable (small model). 25 bytes.
|
||||
; void sort( int num, int a[] );
|
||||
;
|
||||
; Courtesy of David Stafford.
|
||||
;--------------------------------------------------------------------------
|
||||
|
||||
.model small
|
||||
.code
|
||||
public _sort
|
||||
.model small
|
||||
.code
|
||||
public _sort
|
||||
|
||||
top: mov dx,[bx] ;swap two adjacent integers
|
||||
xchg dx,[bx+2]
|
||||
xchg dx,[bx]
|
||||
cmp dx,[bx] ;did we put them in the right order?
|
||||
jl top ;no, swap them back
|
||||
inc bx ;go to next integer
|
||||
inc bx
|
||||
loop top
|
||||
_sort: pop dx ;get return address (entry point)
|
||||
pop cx ;get count
|
||||
pop bx ;get pointer
|
||||
push bx ;restore pointer
|
||||
dec cx ;decrement count
|
||||
push cx ;save count
|
||||
push dx ;restore return address
|
||||
jg top ;if cx > 0
|
||||
top: mov dx,[bx] ;swap two adjacent integers
|
||||
xchg dx,[bx+2]
|
||||
xchg dx,[bx]
|
||||
cmp dx,[bx] ;did we put them in the right order?
|
||||
jl top ;no, swap them back
|
||||
inc bx ;go to next integer
|
||||
inc bx
|
||||
loop top
|
||||
_sort: pop dx ;get return address (entry point)
|
||||
pop cx ;get count
|
||||
pop bx ;get pointer
|
||||
push bx ;restore pointer
|
||||
dec cx ;decrement count
|
||||
push cx ;save count
|
||||
push dx ;restore return address
|
||||
jg top ;if cx > 0
|
||||
|
||||
ret
|
||||
ret
|
||||
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
#### Full 32-Bit Division {#Heading8}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue