Assembly Homework Help, Project Help, Assembly Assignment Solution

Although assembly language is no longer popular and it is not being widely used in Computer Science, It is still being offered in school to help students understand major concepts of computers. Assembly programming language has two types of syntax: AT&T and Intel. Instead of machine code, it uses symbolic designation of programming elements which can be difficult to understand. If you find this low-level language too confusing then do not hesitate to avail our assembly language assignment help.

Assembly language is no longer widely used because modern compilers in high-level languages like C and Java, mostly use functions that have been optimized and written in assembly programming. Our assembly language programming assignment help experts can help you learn gain more insight on these compilers such as memmove, memset or fillchar and many more. Assembly language still has its advantages. One of the advantages is that it can achieve faster execution time when an algorithm is optimally complex. Programmers can write instructions using assembly language to increase the running speed of programs. It has been proven that assembly language instructions execute five to ten times faster than those written in C or Pascal. Getting assembly language help from ProgrammingHomeworkHelp.com will help you acquire in-depth knowledge on how the microprocessor works and how to write efficient programs. The executable code size is very small and our assembly language tutor will provide you with a detailed explanation on what the program entails.

A utility program known as an assembler is used to convert assembly language into machine code. An assembler program translates combinations of mnemonics and syntax for operations, and address modes into their numerical equivalents to create an object code. It is also responsible for the resolution of symbolic names and the calculation of constant expressions for memory locations. The number of times the source is read determines the type of assembler. There are two types, namely:

  • One-pass assemblers – These types of assemblers go through the source code once. An “errata” will be required at the end of the object code for any symbol used before it is defined. It tells the loader to “go back” and overwrite the placeholder which had been left where the undefined symbol was used.
  • Multi-pass assemblers – These assemblers create a table which contains all the symbols and their values in the first passes. The table is then used in the later passes to generate code.

Assembly language is as close as you can get to the machine, unless you pick up a soldering iron and build one yourself. The earliest computers were programmed using binary code which is very tedious, so one of the first programming languages was assembly language which represents a one to one correspondence between the instruction in the source and the code executed by the processor. Later on macro assemblers were developed which would allow you to substitute a few instructions, possibly conditionally. So for example

print "Welcome"

which could expand to

.section data

    message1: dc.b "Welcome", 0

.section text

    lea a0, message1
    jsr printString

I’ve spent many years working in assembly language for various processors, from the 8 bit processors such as 6502, Z80, then the 68000, 80×86, ARM. I’ve also completed assignments with other processors such as MIPS, LC3 and SPARC.

It is worth learning assembly language even if you never use it as it enables a better understanding of the low level primitives that your code is converted into (for languages such as C, C++, not languages like Java, Python which use bytecode which is a form of
emulated machine code). You can also use small amount of assembly language in a program to optimize a routine that is executed a lot.

Here is a Assembly program to solve the assignment, if you need help with Assembly this is just an example of the style of work we can do for you.

80×86 assembly language

80×86 is the name of the family of processors by Intel (although AMD processors also use the same instruction set). The orignal 80×86 family includes the 8088 which was an 8 bit version of the 8086, the 80286 was used in early IBM AT’s. The 80386 was a 32 bit processor and was used in Windows, the 80586 was just called the Pentium instead of using the numbering.

Some assignments for the 80×86 assume it was an early form of the procesor, and are run using DosEMU or another emulator. When programming in 80×86 you need to worry about the segments, which are used to access different areas of memory as you can only access 64K at a time.


1.Write a proc called qryInt that prompts the user to enter an integer and returns the integer value entered via the EAX register. The prompt string should be passed to the proc as an argument using the stack. The prompt should be displayed using the strput.

.386
.MODEL flat,stdcall
.STACK 4096

;; change the IRVINE32 direction if it is not installed in the bellow folder
INCLUDE      C:\Irvine\Irvine32.inc
INCLUDELIB   C:\Irvine\Irvine32.lib

.data

prompt BYTE "Enter the integer: ", 0

.code

qryInt PROC
    push ebp
    mov ebp, esp
    mov edx, [ebp + 8] ; get the address of the prompt parameter
    call WriteString
    call ReadInt ; read the integer into EAX
    pop ebp
    ret
qryInt ENDP

main PROC
    ; put the address of the prompt onto the stack
    mov eax, OFFSET prompt
    push eax
    call qryInt
    ; the integer should be EAX
    call WriteInt
    exit
main ENDP

END main

2.Write a proc that takes a single string argument, counts the number of characters in the string, and returns the count via the EAX register

.386
.MODEL flat,stdcall
.STACK 4096

;; change the IRVINE32 direction if it is not installed in the bellow folder
INCLUDE      C:\Irvine\Irvine32.inc
INCLUDELIB   C:\Irvine\Irvine32.lib

.data

string BYTE "The length of the string is 30", 0

.code

strlen PROC
    push ebp
    mov ebp, esp
    mov edx, [ebp + 8] ; get the start address of the string
    mov eax, 0         ; initialize length = 0

L1: mov bl, [edx]  ; move the i-th character to BL
    cmp bl, 0      ; if BL = 0, then the end of the string, break the loop
    je L2
    add edx, 1     ; otherwise move EDX to the address next character
    add eax, 1     ; increase the length
    jmp L1  
L2:
    pop ebp
    ret
strlen ENDP

main PROC
    ; put the address of the string onto the stack
    mov eax, OFFSET string
    push eax
    call strlen
    ; length should be at EAX
    call WriteInt
    exit
main ENDP

END main

This is an example Assembly home work. We can custom design the solutions to your skill level (so advanced, intermediate or basic), just let us know.

Each personal computer has a microprocessor which takes care of the arithmetical, logical, and control activities. Our assembly programming assignment help makes the student understand the family of processors.

Mixing C & assembly

Write a program using NASM that will allow the user to enter an integer in base 10 from 0 to 255 and will change the number into base n (where n is from 2 to 9). The user should be allowed to enter different bases until they put in the value 0 (the sentinel value to stop the program). In addition to writing the base conversion on the screen, the base conversions should also be recorded in a text file named by the command-line argument.
You can assume that:
1. The user will enter an integer when prompted for the number, but you must check to see that it is between 0 and 255. Loop until you get a number between 0 and 255.
2. The user will enter an integer when prompted for the new base, but you must check and see if it is between 2 to 9. Loop until you get a number between 2 to 9. The exception is the value 0, which is the sentinel value that will stop the program.
3. The user will always supply one command-line argument (the name of the output file)
You must:
1. Not use any system calls at all
2. Program the logic for converting from base 10 to base n using only assembly (no C).
3. Use only the following C functions: printf, scanf, puts, fopen, fclose, fprintf
4. Design your program to run exactly like the sample run.
5. Create your project using:
nasm -f elf -g -F stabs proj4.asm
gcc -o proj4 proj4.o -m32

Source Code:

Makefile

all: proj4.asm
    nasm -f elf -g -F stabs proj4.asm
    gcc -dynamic-linker -s -o proj4 proj4.o -m32 -lc -I/lib/ld-linux.so.2

clean:
    rm -f proj4.o proj4

 proj4.asm


    SECTION .data       ; data section
msg:    db "Enter a number between 0 and 255: ",0
msg2:   db "Enter a base between 2 and 9: ",0

formatin: db "%d",0
format1: db "%d",10,0
format2: db "%s",10,0
newline:  db 10,0
filemode: db "w",0

    SECTION .bss            ; global variable section
v:      resb 4 
base:   resb 4
count:  resb 4
file:   resb 4

    SECTION .text       ; code section
        global main     ; make label available to linker 
        extern printf
        extern scanf 
    extern fopen
    extern fclose
    extern fprintf
main:               ; standard  gcc  entry point
    ; setup the stack frame
    push EBP
    mov EBP, ESP

    ; assume the first parameter is the file to output
    ; open the file
    mov EBX, dword [EBP + 12]
    add EBX, 4 ; point to the second string in the array

    push dword filemode
    push dword [EBX]
    call fopen
    ; now EAX has the return value, which is the file pointer
    mov [file], EAX

start:
        ; print the message
    push dword msg
    call printf
    add ESP, 4

        ; read the user's input
    push v
    push dword formatin
    call scanf
    add ESP, 8

    ; check if v is between 0 and 255
    mov EAX, dword [v]
    cmp EAX, dword 0 
    jl start
    cmp EAX, dword 255 
    jg start

ask_base:
    ; print the message
    push dword msg2
    call printf
    add ESP, 4
    ; read the base
    push dword base
    push dword formatin
    call scanf
    add ESP, 8

    ; check if base is 0
    mov EAX, dword [base]
    cmp EAX, dword 0
    je exit

    ; check if base is between 2 and 9
    mov EAX, dword [base]
    cmp EAX, 2
    jl ask_base
    cmp EAX, 9
    jg ask_base

    ; now v and base have validate values
    mov EAX, dword [v]
    mov EBX, dword [base]
    ; count is used to remember the number of values on the stack
    mov dword [count], dword 0
next:   
    ; increase the count
    mov EDX, dword [count]
    inc EDX
    mov dword [count], EDX
    xor EDX, EDX

    div EBX

    ; EAX has quotient, EDX has remainder
    ; put the remainder on to the stack
    push EDX

    cmp EAX, dword 0
    jne next

    ; now the remainders are on the stack
    ; continue put 0 onto the stack until the count is 8
fill:
    mov ECX, dword [count]
    cmp ECX, dword 8
    jge print
    push dword 0
    inc ECX
    mov dword [count], ECX
    jmp fill

print:  ; output 8 words on the stack and in the file
    mov EDX, dword [count]
    cmp EDX, dword 0
    jle done_print 
    dec EDX
    mov dword[count], EDX
    push dword formatin
    call printf
    push dword [file] ; fprintf(file, ..)
    call fprintf
    add ESP, 12
    jmp print

done_print:
    push dword newline
    call printf
    push dword [file]
    call fprintf
    add ESP, 8
    jmp ask_base

exit:
    ; close the file
    push dword [file]
    call fclose
    add ESP, 4
    ; destroy the stack frame
    mov ESP, EBP
    pop EBP
    ret

Below you should find a sample Assembly assignment, I’ve had to provide multiple solutions to assignments, and can alter the code to match your style.

20 assembly language programs

CPSC 355: Computing Machinery I
Project Specification
300 points
Due Dates:
1. Test case submission: March 7
2. Codebase Submission (review/feedback only): March 31
3. Demonstration: April 7..14 (in tutorial, class, & by appointment)
– please be sure to sign up for an available demo slot
4. Final code submission (immediately after demo, via SVN)

[Project Statement]

In this project, you will build an 8088 assembler. The job of your assembler is to turn 8088 assembly code (i.e., the 8086 assembly code language) into 8088 machine code that executes in an DOS emulator. The wiki page lists links to two different DOS emulators. You have been given a paper copy of part of the 8088 data sheet, as well as a variety of links to documentation about the 8088, its ISA, its
instruction set, and its execution semantics.

[Purpose]

This kind of project is a comprehensive test of the skills and knowledge you obtain throughout the course. It is a replacement for
the final exam, and should be approached with the dedication and purpose one would put into studying for a final exam. Even though it
replaces the final exam as a course component, there are several due dates throughout the semester. Please be aware of them, as late work
is not accepted.

This project is an opportunity for students to demonstrate understanding of a concrete, specific Instruction Set Architecture
(ISA) and general CPU organization concepts and design philosophies (CISC vs. RISC), the instruction formats and addressing modes, the
data path and fetch-decode-execute cycle, memory addressing, number systems and encodings, a practical and realistic knowledge of C
programming, among the other topics listed in the course syllabus. Students must demonstrate their solution by both submitting their code
and demonstrating the software to the instructor.

The instructor believes that students at this point in the CPSC curriculum can and should be able to write a basic assembler using the
C programming language. The intent of the project is not for students to write a NASM, AS, or GAS replacement, but rather a simple and functional assembler that does basic assembly of instruction mnemonics into byte values. The core of this assembler should contain file I/O code that tokenizes lines of text (i.e., each line of an assembly source file), maintains a symbol and label table, and then translates these tables into a sequence of bytes that represents each instruction; the sequence should be written to a file containing the
binary code and be executable as a 16-bit DOS .COM executable for the x86 platform (hint: see the nasm -hf output and the description of output formats in the NASM documentation, specifically the ‘bin’format — links are on the wiki).

A significant number of early tutorials are dedicated to the C programming language, including standard libraries and functions that students will find useful in doing the file I/O and manipulation of the data representing each instruction. Likewise, students should
become comfortable with writing assembly language programs in the x86 language. Students should also be able to use tools like nasm,
ndisasm, objdump, and udcli to compare the output of their assembler with standard tools.

[Learning Outcomes]

Below is a list of anticipated learning outcomes for students, including but not limited to:

  • develop fluency with the C language and libraries
  • reinforce programming skills from previous CPSC courses
  • acquire experience writing real assembly programs
  • become familiar with a simple but real computer architecture and machine, complementing the theoretical study of the SPARC and x86 ISAs from class material
  • become acquainted with the semantics of a real instruction set and formats
  • create an element of a professional portfolio
  • develop and reinforce number systems knowledge and translation skills; bit manipulation
  • clearly understand the link between constructs expressed at the ISA level and the bit values interpreted by the machine hardware
  • develop a foundation of basic parsing concepts
  • practice “speaking machine” through the specification of translation routines
  • gain understanding of how high-level source constructs like variables and control flow artifacts are represented and interpreted at the machine level

[Rules / Specifications]

  1. This is an individual project. You may not receive help from other students or professionals. You may use any public reference
    material you wish, including those provided by the instructor. Evidence of collusion will be treated seriously and referred to the official University process for dealing with academic dishonesty. You may not simply re-purpose existing assembler code, or pass input assembly code to an already-existing assembler such as NASM or AS. Your assembler should be of your own design and conception.
  2. We will provide an execution harness for executing your assembled program. In other words, you do not have to worry about packaging your assembled code as an ELF file: the output file should be a flat sequence of bytes (similar to the ‘nasm -f bin’ output option) and named as a DOS .COM file (e.g., MYPROG.COM). The output programs should run under DOSBOX or FreeDOS.
  3. Your work on this project will be assessed at three separate times:

(1) at the midpoint of the semester, as indicated by the deadline above, you must submit a set of valid 8088 assembly programs that forms your test SUITE. This milestone provides you with an opportunity to practice your knowledge of assembly code, machine instruction formats for a CISC architecture, and get a small portion of the project done. The test suite should contain freshly written programs (i.e., you should not simply
resubmit a previous HW assignment answer as a test case). For maximum marks, you should have a significant number test cases of significant complexity. Each test program should be properly formatted and every line should be commented. The file should begin with a comment describing the rationale for including it in the test suite (i.e., it should document what feature(s) of your assembler this test case is meant to
assess). You should write these test cases before you write your assembler. The instructor anticipates that your assembler may not successfully assemble all of your test cases especially if you create some really complex test cases); that’s fine — your grade for this component is based on the quality and number of test cases, not whether your assembler correctly processes them all.

(2) about 2 weeks before the end of the semester, the submission of the basic core of the assembler code, e.g., something that parses lines of assembly mnemonics and dispatches to the appropriate translation routine for the given instruction. Basically, this codebase should reflect at least the “D” level of work (see the table below). This component is for feedback purposes only; it is not graded as such, but you WILL lose 10%
of the points available for this project if you do not submit something that compiles (without warnings) and “works” at the D level.

(3) during the last week, individual demonstrations to the instructor during tutorial sessions of the full capabilities of your assembler, plus the immediate submission of its code as demo’d (this version of the code is graded per the table below).

One benefit about this kind of project is that each major component can be accomplished to a greater or lesser degree depending on student talent, interest, and time. Here is a table relating the various elements of the project to the grade levels represented by degree of completion for each element. The grade levels map to a number of points out of 300.

          =============================================
                           Grade Level
          =============================================
              D        C         B       A           A+
-------------------------------------------------------
Features
=======================================================
#passes      >3        3         2       1+partial    1
                                           fwd scan
-------------------------------------------------------
#instr.
 supported    5       10         20      40         >40
-------------------------------------------------------
#addressing
 modes        1       2          5       6           >6
 supported
-------------------------------------------------------
# test
 programs   [1..2]  [3..5]   [6..10]    [11..20]    >20
-------------------------------------------------------
ctrl flow   none  straight    back jmp  fwd jmp   +self
                  line
-------------------------------------------------------
error       none   basic      syntax    semantic   ...
reporting
-------------------------------------------------------
other
features      (s e e   b e l o w)
&docs
-------------------------------------------------------
demo @ a feature level to prof.
-------------------------------------------------------
max pts:    192     222        258        291       300

“other features and documentation” includes items like: appropriate file I/O and error handling conversion between decimal, hex, and binary hard coded or dynamic program and symbol table sizes presence of symbol tables, program tables, address tables support for comments and basic parsing a data structure for representing instructions support for memory reference syntax, register names, etc.
clean parsing, ignore whitespace, mixed case, etc.

This specification is subject to update and feedback as necessary

1

;Very basic example, should be the first program
;that the assembler can compile
;It includes a jump to a label, db to enter data
;and int routine to call the system

        org 100h            ;start address

        jmp start   ;branch over the text

msg:    db      "Hello, World!", 0Dh,0Ah, '$'

start:  mov     dx, msg     ;get the text to be disp;ayed
        mov     ah, 9       ;the print command 
        int     21h         ;print string

        mov     ah, 0       ;wait for a key command
        int     16h         ;wait for key

        ret                 ;exit the program

2

;Simple examples, calls a function to print al in decimal
;The code uses recursion, proc, endp, div instructions

    org 100h

    mov al, 108     ; al will store the number to be displayed

    call print_al   ; print al in decimal:

    mov ah, 0
    int 16h         ; wait for any key press

    ret

;Display al in decimal
;Does not modify any registers
print_al proc
    cmp al, 0       ; is it 0?
    jne print_al_recursive      ;no
    push ax         ;save ax
    mov ax, 0e30h   ;ah = 0eh al = '0'
    int 10h         ;print single character
    pop ax          ;restore ax
    ret             ;simple case, of 0
print_al_recursive:    
    push ax         ;save ax, dx registers
    push dx
    xor ah, ah      ;mov ah, 0
    and ax, ax      ;cmp ax, 0
    je print_al_exit    ;equal to 0, exit
    mov dl, 10      ;divide by 10
    div dl          ;al = ah:al / dl
    call print_al_recursive ;do it again
    mov al, ah      ;get the remainder
    add al, '0'     ;convert to character
    mov ah, 0eh     ;output character
    int 10h    
print_al_exit:
    pop dx
    pop ax          ;restore registers in reverse order
    ret  
endp

3

;Simple program that modifies a character
;Uses xor to switch case

        org     100h        ;start address

        jmp     start       ;goto the code

msg:    db      "Enter a letter: $"

start:  mov     dx, msg     ;display prompt
        mov     ah, 9 
        int     21h         ;print string

        mov     ah, 0       ;wait for a key
        int     16h

        mov     ah, 0Eh     ;print character
        int     10h

        xor     al, 32      ;upper to lower, lower to upper

        mov     ah, 0Eh     ;print character
        int     10h

        mov     ah, 0 
        int     16h         ;wait for key

        ret

4

;Identify a key, uses conditional instructions

        org     100h    ;start address

        jmp     start   ;goto the code

msg:    db      "Press a key: $"
notletter:  db  "That was not a letter or a number$"
lowercase:  db  "That was a lowercase letter$"
uppercase:  db  "That was an uppercase letter$"
number: db      "That was a number$"

start:  mov     dx, msg     ;inital prompt
        mov     ah, 9 
        int     21h         ;print string

        mov     ah, 0       ;wait for a key
        int     16h

        mov     ah, 0Eh     ;print character
        int     10h

        mov     cx, notletter   ;going to use this a few times
        mov     dx, cx 
        cmp     al, '0'     ;not letter/number
        jl      output      ;< 0
        mov     dx, number  ;it might be a number
        cmp     al, '9'
        jle     output      ;yes it is
        mov     dx, cx      ;mot a letter/number message
        cmp     al, 'A'
        jl      output      ;not a letter
        mov     dx, uppercase   ;might be upper case
        cmp     al, 'Z'
        jle     output      ;yes it was
        mov     dx, cx      ;not a letter/number
        cmp     al, 'a'     
        jl      output      ;yep, not a letter/number
        cmp     al, 'z'     ;check if it is lowercase
        jg      output      ;no, it isn't
        mov     dx, lowercase   ;it is lowercase     
output:        
        mov     ah, 9
        int     21h         ;print string
finish:        
        mov     ah, 0 
        int     16h         ;exit

        ret

5

;Command line echo, uses indirection and displays the command line

        org 100h            ;start address

        jmp start

start:  xor     bx, bx      ;less bytes than mov dx, 0
        mov     bl, [0x80]  ;get the length
        add     bl, 0x81    ;add the start position
        mov     [bx], 10    ;add lf
        mov     [bx+1], 13  ;add cr
        mov     [bx+2], '$' ;add terminating $

        mov     dx, 0x82    ;command line

        mov     ah, 9 
        int     21h         ;print string

        ret

6

;command line version of echo, that displays in upper case
;use indirection

        org 100h            ;start address

start:  xor     bx, bx      ;less bytes than mov bx, 0
        mov     bl, [0x80]  ;get the length        
        add     bl, 0x81    ;add the start position
        mov     [bx], 10    ;add lf
        mov     [bx + 1], 13     ;add cr
        mov     [bx + 2], '$'    ;add terminating $
next:   dec     bl          ;go backwards
        mov     al, [bx]    ;read byte
        cmp     al, 'a'     ;check if it is lowercase
        jl      notlower
        cmp     al, 'z'
        jg      notlower    ;it is not lowercase
        sub     al, 32
        mov     [bx], al    ;convert to uppercase
notlower:
        cmp     bl, 0x81    ;reached start
        jnz     next
        mov     dx, bx      ;command line

        mov     ah, 9 
        int     21h         ;print string

        ret

7

;Simple test of user defined macro

        org 100h    ;Start of code

print   MACRO   string  ;Macro to display a string
        local   label1, label2  ;Labels
        jmp     label2          ;Jump over the text
label1: db      string, 0xD, 0xA, '$'   ;The text
label2: mov     dx, label1  ;Load the text
        mov     ah, 9
        int     21h     ;print the string
        ENDM

start:
        print   "Hello, World!"     ;Display string
        print   "Powered by Macros!!!"  ;And another (to make sure local works)

        ret

8

;Read a hexadecimal value from command line

        org 100h            ;start address

        xor ax, ax          ;the hex value
        mov bx, 0x82        ;first character of command line
        mov cl, [0x80]      ;size in bytes of command line
        dec cl              ;account for space
        jle finished        ;0 if no value
        xor dx, dx          ;each digit we are adding
nextdigit:        
        mov dl, [bx]        ;current digit
        inc bl              ;don't need to worry about page boundary
        sub dl, '0'         ;convert digit to number         
        jl  finished        ;not a number/digit
        and dl, 31          ;convert lowercase to uppercase
        add ax, ax
        add ax, ax
        add ax, ax
        add ax, ax          ;shift by 4 (* 16)
        cmp dl, 10          ;more than 10 (so alphabetical)
        jl  addtototal
        sub dl, 7           ;convert A to 11
addtototal:
        add ax, dx          ;add to the value
        loop nextdigit      ;more digits remaining

finished:
        call print_ax       ; print result in decimal:

        ret

print_ax    proc
        cmp ax, 0           ;check for 0
        jne print_ax_recursive
        push ax             ;save ax
        mov ax, 0e30h       ;ah = 0eh al = '0'
        int 10h             ;print single character
        pop ax              ;restore ax
        ret                 ;exit 
print_ax_recursive:    
        pusha               ;push all the registers
        xor dx, dx          ;dx = 0
        cmp ax, dx          ;is ax = 0?
        je print_ax_exit    ;yep, so don't print
        mov bx, 10          ;divide by 10
        div bx              
        call print_ax_recursive ;call recursive
        mov al, dl          ;get the digit
        add al, '0'         ;convert to ascii
        mov ah, 0eh
        int 10h             ;display the character    
print_ax_exit:
        popa                ;restore all the registers  
        ret  
endp                        ;end the procedure

9

;Demonstrates number printing, with text and loops
;To display the lyrics of 99 Bottles of Beer on the wall

        org     100h        ;start

        jmp     start       ;goto the code

bottles: db      " bottles of beer on the wall, $"
takeone: db      " bottles of beer.", 10, 13
        db      "You take one down and pass it around, and there are", 10, 13, '$'
nomore:  db      "no more bottles of beer of the wall, no more bottles of beer.$"

start:
        mov     cx, 99      ;number of bottles to start with
songloop:
        mov     al, cl      ;get the number of bottles

        call    print_al    ;print number of bottles

        mov     dx, bottles ;first line of song
        mov     ah, 9 
        int     21h         ;print string

        mov     al, cl      ;print the number again
        call    print_al

        mov     dx, takeone ;next line of song
        mov     ah, 9 
        int     21h         ;print string

        loop    songloop    ;loop until no more bottles

        mov     dx, nomore  ;display last line of song
        mov     ah, 9 
        int     21h         ;print string

        mov     ah, 0
        int     16h         ; wait for any key press

        ret

;Display al in decimal
;Does not modify any registers
print_al proc
        cmp     al, 0       ; is it 0?
        jne     print_al_recursive      ;no
        push    ax         ;save ax
        mov     ax, 0e30h   ;ah = 0eh al = '0'
        int     10h         ;print single character
        pop     ax          ;restore ax
        ret             ;simple case, of 0
print_al_recursive:    
        push    ax         ;save ax, dx registers
        push    dx
        xor     ah, ah      ;mov ah, 0
        and     ax, ax      ;cmp ax, 0
        je      print_al_exit    ;equal to 0, exit
        mov     dl, 10      ;divide by 10
        div     dl          ;al = ah:al / dl
        call    print_al_recursive ;do it again
        mov     al, ah      ;get the remainder
        add     al, '0'     ;convert to character
        mov     ah, 0eh     ;output character
        int     10h    
print_al_exit:
        pop     dx
        pop     ax          ;restore registers in reverse order
        ret  
endp

10

;This program draws color bars in vga mode. Uses equ

        name    "color_bars"    ;ignored

        org     100h

height  equ     200   ;height of the bars

        mov     ax, 13h 
        int     10h         ;set video mode 13h - 320x200

        mov     cx, 256     ;x position
forx:   xor     dx, dx      ;y position
fory:   mov     al, cl      ;color
        mov     ah, 0ch     ;put pixel
        int     10h
        inc     dl          ;next line
        cmp     dl, height  ;reached the height
        jne     fory        ;loop to draw vertical
        loop    forx        ;loop to draw next x

        xor     ah, ah
        int     16h         ;wait for keypress

        ;return to text mode:
        mov     ax, 03      ;text mode 3
        int     10h

        ret

11

;Direct VGA access (modifying segment registers)

        name    "color_bars2"

; this program draws color bars in vga mode.

        org     100h    ;start address

height  equ     200     ;height of the bars

        mov     ax, 13h ;set video mode 13h - 320x200
        int     10h
        mov     ax, 0xA000  ;VGA memory
        mov     es, ax      ;segment register

        mov     cx, 256     ;x position
forx:   mov     di, cx      ;y position
        mov     al, cl      ;color
        mov     dl, height  ;number of pixel
fory:   mov     es:[di], al ;put pixel
        add     di, 320     ;next line
        dec     dl          ;any more
        jne     fory        ;yes
        loop    forx        ;next line

        mov     ah,00
        int     16h         ;wait for keypress

        ;return to text mode:
        mov     ax, 03      ;text mode 3
        int     10h

        ret                 ;return to os

12

;Reading from command line, and passing to function
;Checks rep instruction

        org 100h

command_line    equ 0x82       ;command line starts here

start:
        xor bx, bx          ;want to add null terminator
        mov bl, [0x80]      ;get the length
        add bx, 0x81        ;get the start
        mov [bx], bh        ;write a 0 at end

        call clean_name     ;clear the output buffer

        mov ah, 0x1A        ;Set DTA table adress
        mov dx, DTA
        int 21h             ;Directory search needs a buffer

        call clean_name     ;Fill filename with 0s

        mov ah, 0x4E        ;Get first file
        xor cx, cx          ;Not searching for any type
        mov dx, command_line    ;search
        int 21h
        jc finish           ;No files matching query found

        mov ah, 9
        mov dx, filename    ;Display filename
        int 21h

        call clean_name     ;Fill filename with 0s

find_next:

        mov ah, 0x4F        ;Get next file
        mov dx, command_line
        int 21h             ;Find next matching file
        jc finish           ;No more files found

        mov ah, 9
        mov dx, filename    ;Display filename
        int 21h

        call clean_name     ;Clear the text

        jmp find_next       ;More file

finish:
        ret                 ;Exit program

clean_name:
        mov cx, 14          ;Number of bytes to 0
        mov di, filename    ;Clear file
        xor ax, ax          ;Zero the text
        rep stosb           ;Fill name with zeros incase memory has some ugly stuff or smth left from last search
        ret

DTA:    db "0123456789abcdefghijk"    ;21 bytes DOS data
attrib: db 0x0  ;attribute
time:   dw 0x0  ;creation/modification time
date:   dw 0x0  ;creation/modification date
size:   dw 0x0  ;file size
sizehi: dw 0x0
filename:  db "0123456789abc", 0, 0 ; file name terminated with zero (13 chars)
        db 0xD, 0xA ; New line
        db "$" ; 0xD - tells DOS to go to new line.

13

;Convert fahrenheit to centigrade (32F and greater)
;Uses lodsb

        org 100h            ;start address

        xor ah, ah          ;we want to read bytes
        xor bx, bx          ; bx will store the total
        mov si, 0x82
        mov cl, [0x80]      ;size in bytes of command line
        dec cl
        jle finished        ;no digits present
nextdigit:
        lodsb               ;read character
        sub al, '0'         ;get the digit
        jl  finished        ;end of number
        push ax             ;need to multiply exisitng value by 10
        mov ax, bx          ;mul only works on ax
        mov dx, 10          ;multiply by 10
        mul dx              ;ax = bx * 10
        mov bx, ax          ;bx is shifted
        pop ax              ;restore the character
        add bx, ax          ;add to the total
        loop nextdigit      ;whilst there are more digits

finished:
        sub bx, 32          ;c = (f-32)/9*5
        mov ax, bx          ;to keep precision multiply first
        mov dx, 50
        mul dx              ;multiply by 50 (so we have 1 decimal place)
        xor dx, dx          ;upper part must by 0
        mov cx, 9           
        div cx              ;divide by 9
        xor dx, dx          ;clear it (for divide)
        mov cx, 10          ;divide by 10
        div cx              ;dx = .0 to .9

        call print_ax       ;print result in decimal:
        push dx
        mov ah, 2           ;print character function.
        mov dl, '.'         ;print '.'
        int 21h
        pop ax              ;restore original value from dx to ax
        call print_ax       ;print the remainder

        ret                 ;exit the program

print_ax    proc
        cmp ax, 0           ;check for 0
        jne print_ax_recursive
        push ax             ;save ax
        mov ax, 0e30h       ;ah = 0eh al = '0'
        int 10h             ;print single character
        pop ax              ;restore ax
        ret                 ;exit 
print_ax_recursive:    
        pusha               ;push all the registers
        xor dx, dx          ;dx = 0
        cmp ax, dx          ;is ax = 0?
        je print_ax_exit    ;yep, so don't print
        mov bx, 10          ;divide by 10
        div bx              
        call print_ax_recursive ;call recursive
        mov al, dl          ;get the digit
        add al, '0'         ;convert to ascii
        mov ah, 0eh
        int 10h             ;display the character    
print_ax_exit:
        popa                ;restore all the registers  
        ret  
endp                        ;end the procedure

14

;Decimal to hexadecimal display

        org 100h            ;Start address


        xor ah, ah          ;we want to read bytes
        xor bx, bx          ; bx will store the total
        mov si, 0x82
        mov cl, [0x80]      ;size in bytes of command line
        dec cl
        jle finished        ;no digits present
nextdigit:
        lodsb               ;read character
        sub al, '0'         ;get the digit
        jl  finished        ;end of number
        push ax             ;need to multiply exisitng value by 10
        mov ax, bx          ;mul only works on ax
        mov dx, 10          ;multiply by 10
        mul dx              ;ax = bx * 10
        mov bx, ax          ;bx is shifted
        pop ax              ;restore the character
        add bx, ax          ;add to the total
        loop nextdigit      ;whilst there are more digits

finished:
        mov ax, bx          ;we want to display bx
        call print_ax_hex   ;value is in ax

        ret

print_ax_hex    proc
        push ax             ;save the registers
        push dx
        mov dx, prefix      ;use 0x before number
        mov ah, 9 
        int 21h
        pop dx              ;restore the registers
        pop ax        
        and ax, ax          ;cmp ax, 0
        jne print_ax_hex_recursive
        push ax
        mov ax, 0e30h       ;ah = 0eh al = '0'
        int 10h             ;print single character
        pop ax              ;restore ax
        ret                 ;return
print_ax_hex_recursive:    
        pusha               ;save all registers
        xor dx, dx          ;dx = 0
        cmp ax, dx          ;check for 0
        je print_ax_hex_exit    ;stop at 0
        mov bx, 16          
        div bx              ;divide by 16
        call print_ax_hex_recursive
        mov al, dl          ;get the character
        add al, '0'         ;convert to ascii
        cmp al, '9'         ;check for > '9'         
        jle print_ax_hex_digit
        add al, 7           ;to get uppercase hex character
print_ax_hex_digit:        
        mov ah, 0eh         ;display character
        int 10h    
print_ax_hex_exit:
        popa                ;restore all registers
        ret  
endp

prefix: db  "0x$"           ;starts hex values

15

;Test of macro, uses call and pop to get the address of parameters

        org 100h    ;Start of code

print   MACRO   string  ;Macro to display a string
        local   label   ;Labels
        call    label          ;Jump over the text
        db      string, 0xD, 0xA, '$'   ;The text
label:  pop     dx      ;Load the text
        mov     ah, 9
        int     21h     ;print the string
        ENDM

start:
        print   "Hello, World!"     ;Display string
        print   "Powered by Macros!!!"  ;And another (to make sure local works)

        ret

16

;command line rot 13 encoder/decoder
;uses xlatb, lodsb, stosb

        org 100h            ;start address

start:  xor     cx, cx      ;less bytes than mov cx, 0
        mov     cl, [0x80]  ;get the length
        mov     dx, 0x82    ;Start at the text
        mov     si, dx      ;Source register
        mov     di, dx      ;Destination register
        mov     bx, rot13table  ;Translation table

next:   lodsb               ;Load a byte from [si], and increment
        xlatb               ;al = [bx + al]
        stosb               ;Store a byte [di] and increment
        loop    next        ;Go through the loop
        mov     al, 10      ;Add lf
        stosb               ;Store it
        mov     al, '$'     ;Add terminating $
        stosb               ;Store it

        mov     ah, 9       ;the print command 
        int     21h         ;print string

        ret                 ;return to os

rot13table:
        db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
        db 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
        db ' ','!','"','#','$','%','&',"'",'(',')','*','+',',','-','.','/'
        db '0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?'
        db '@','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B'
        db 'C','D','E','F','G','H','I','J','K','L','M','[','\',']','^','_'
        db '`','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b'
        db 'c','d','e','f','g','h','i','j','k','l','m','{','|','}','~',127
        db 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143
        db 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159
        db 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175
        db 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191
        db 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207
        db 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223
        db 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239
        db 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255

17

; this example calculates the sum of a vector with
; another vector and saves result in third vector.
; uses std (direction flag), and ? in db statement
; and calculated difference (pi - numbers), stc, adc

        org 100h        ;start address

        jmp start       ;jump to code

numbers:
        db "314159265359"
pi:        
        db "271828182846"
e:
        ;  "585987448205" expected value        
value:  db ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
total:
        db 10, 13, '$'

start:  lea si, pi - 1
        lea bx, e - 1
        lea di, total - 1
        mov cx, pi - numbers
        std

sum:    lodsb           ;get byte from pi
        adc al, [bx]    ;add the 2 values
        sub al, '0'     ;since we are using ascii twice
        dec bx          ;no autodecrement for bx
        cmp al, '9'     ;do we need to adjust it?
        clc             ;clear the carry flag (set by cmp)
        jle nocarry     ;no carry needed
        sub al, 10      ;adjust it
        stc             ;set carry flag
nocarry:stosb           ;store the byte

        loop sum        ;get the next digit

        mov dx, value   ;display the ascii result
        mov ah, 9       ;the print command 
        int 21h         ;print string

        ret

18

;Perform calculations on two hex values (or, and, xor)
;Checks for dw ? at the emd of file (should not increase size?)

        org 100h            ;start address

        xor ax, ax          ;the hex value
        mov bx, 0x82        ;first character of command line
        mov cl, [0x80]      ;size in bytes of command line
        dec cl              ;account for space
        jle finished        ;0 if no value
        xor dx, dx          ;each digit we are adding
nextdigit:        
        mov dl, [bx]        ;current digit
        inc bl              ;don't need to worry about page boundary
        sub dl, '0'         ;convert digit to number         
        jl  finished        ;not a number/digit
        and dl, 31          ;convert lowercase to uppercase
        add ax, ax
        add ax, ax
        add ax, ax
        add ax, ax          ;shift by 4 (* 16)
        cmp dl, 10          ;more than 10 (so alphabetical)
        jl  addtototal
        sub dl, 7           ;convert A to 11
addtototal:
        add ax, dx          ;add to the value
        loop nextdigit      ;more digits remaining

finished:
        mov num1, ax        ;store the first number

nextdigit2:        
        mov dl, [bx]        ;current digit
        inc bl              ;don't need to worry about page boundary
        sub dl, '0'         ;convert digit to number         
        jl  finished2       ;not a number/digit
        and dl, 31          ;convert lowercase to uppercase
        add ax, ax
        add ax, ax
        add ax, ax
        add ax, ax          ;shift by 4 (* 16)
        cmp dl, 10          ;more than 10 (so alphabetical)
        jl  addtototal2
        sub dl, 7           ;convert A to 11
addtototal2:
        add ax, dx          ;add to the value
        loop nextdigit2     ;more digits remaining

finished2:
        mov num2, ax        ;store the second number

        mov cx, ax          ;calculate the result in cx
        mov bx, num1        ;get the address of num1
        mov ax, [bx]        ;get the value from num1

        and cx, ax          ;and the 2 values
        mov dx, andmsg      ;the operation

        call print_both     ;display the result

        or cx, ax           ;ax = num2, cx = num1
        mov dx, ormsg       ;the operation

        call print_both     ;display the result

        xor cx, ax          ;ax = num2, cx = num1
        mov dx, xormsg      ;the operation

        call print_both     ;display the result

        ret

;Print num1 op num2 = result
;Op in dx, result in cx        
print_both:
        mov bx, num1        ;get the first number
        mov ax, [bx]        ;read it from memory
        push ax             ;save a copy
        call print_ax_hex   ;display it
        mov ah, 9
        int 21h             ;display the operand
        mov bx, num2        ;get the second number
        mov ax, [bx]        ;read it from memory
        call print_ax_hex   ;display it
        mov dx, equals
        mov ah, 9
        int 21h             ;display equals message
        mov ax, cx
        call print_ax_hex   ;display the result
        mov dx, crlf
        mov ah, 9
        int 21h             ;start a new line
        mov ax, [bx]        ;read ax from num2
        pop cx              ;cx = [num1]
        ret

print_ax_hex    proc
        push ax             ;save the registers
        push dx
        mov dx, prefix      ;use 0x before number
        mov ah, 9 
        int 21h
        pop dx              ;restore the registers
        pop ax        
        and ax, ax          ;cmp ax, 0
        jne print_ax_hex_recursive
        push ax
        mov ax, 0e30h       ;ah = 0eh al = '0'
        int 10h             ;print single character
        pop ax              ;restore ax
        ret                 ;return
print_ax_hex_recursive:    
        pusha               ;save all registers
        xor dx, dx          ;dx = 0
        cmp ax, dx          ;check for 0
        je print_ax_hex_exit    ;stop at 0
        mov bx, 16          
        div bx              ;divide by 16
        call print_ax_hex_recursive
        mov al, dl          ;get the character
        add al, '0'         ;convert to ascii
        cmp al, '9'         ;check for > '9'         
        jle print_ax_hex_digit
        add al, 7           ;to get uppercase hex character
print_ax_hex_digit:        
        mov ah, 0eh         ;display character
        int 10h    
print_ax_hex_exit:
        popa                ;restore all registers
        ret  
endp

prefix: db "0x$"           ;starts hex values
andmsg: db " & $"
ormsg:  db " | $"
xormsg: db " ^ $"
equals: db " = $"
crlf:   db 10, 13, '$'
num1:   dw ?
num2:   dw ?

19

;Calculate primes and display them (using sieve)

        org 100h            ;start address

        mov cx, 512         ;1024 bytes         
        mov di, primes      ;clear table
        mov bx, di          ;bx is used to fill table
        xor ax, ax              
        rep stosw           ;clear table

        mov al, 1           ;not a prime
        mov dx,2            ;prime number
        call fillprimes     ;sieve the table
        mov dx,3            ;prime
        call fillprimes     ;sieve
        mov dx,5
        call fillprimes
        mov dx,7
        call fillprimes
        mov dx,11
        call fillprimes
        mov dx,13
        call fillprimes
        mov dx,17
        call fillprimes
        mov dx,19
        call fillprimes
        mov dx,23
        call fillprimes
        mov dx,29
        call fillprimes
        mov dx,31           ;prime (sqrt 1024 is 32, so last one)
        call fillprimes     ;sieve
        mov primes, al      ;0 is not prime
        mov primes + 1, al  ;neither is 1

        mov cx, 1024        ;size of primes
        mov si, primes      ;address of primes
        mov bx, 12          ;11 per line (+1 on first line)
printloop:        
        lodsb               ;get byte from table
        and al, al          ;was it prime
        jne notprime        ;if set, then it wasn't
        mov ax, si          ;get the index
        sub ax, primes + 1  ;+1 to account for autoincrement
        call print_ax       ;display prime
        mov dx, comma       ;get the text to be displayed
        dec bx              ;more values on line
        jne endline         ;reached the end of line
        mov dx, crlf        ;display end of line
        mov bx, 11          ;11 values per line
endline:
        mov ah, 9           ;the print command 
        int 21h             ;print string
notprime:
        loop printloop      ;check the next value

        ret

fillprimes:
        mov si, dx          ;index register si
fillprimes1:        
        add si, dx          ;mark multiples of dx as non prime
        mov cx, si          ;check for end of table
        cmp cx, 1024        ;reached the end
        jge fillprimes2     ;stop the end
        mov [bx + si], al   ;mark as non prime
        jmp fillprimes1     ;loop until complete
fillprimes2:
        ret

print_ax    proc
        cmp ax, 0           ;check for 0
        jne print_ax_recursive
        push ax             ;save ax
        mov ax, 0e30h       ;ah = 0eh al = '0'
        int 10h             ;print single character
        pop ax              ;restore ax
        ret                 ;exit 
print_ax_recursive:    
        pusha               ;push all the registers
        xor dx, dx          ;dx = 0
        cmp ax, dx          ;is ax = 0?
        je print_ax_exit    ;yep, so don't print
        mov bx, 10          ;divide by 10
        div bx              
        call print_ax_recursive ;call recursive
        mov al, dl          ;get the digit
        add al, '0'         ;convert to ascii
        mov ah, 0eh
        int 10h             ;display the character    
print_ax_exit:
        popa                ;restore all the registers  
        ret  
endp                        ;end the procedure

crlf:   db 10, 13, '$'
comma:  db ", $"

primes: db  255 dup ?       ;255 is max for dup
        db  255 dup ?
        db  255 dup ?
        db  255 dup ?
        db  4 dup ?         ;1024 bytes total

20

; showdate.asm
;
; prints the date and time to stdout
; equivalent to the following C++ program:
;
;#include <iostream.h>
;#include <time.h>
;
;int main()
;{
;    time_t t;
;    time(&t);                  // get the current time
;    cout << ctime(&t);         // convert to string and print
;    return 0;
;}
;
; This code may be assembled and linked using Borland's TASM:
;   tasm /la /m2 showdate
;   tlink /Tdc showdate
;
STDOUT                  equ     01h     ; handle of standard output device

DOS_GET_DATE            equ     02ah    ; get system date
DOS_GET_TIME            equ     02ch    ; get system time
DOS_WRITE_HANDLE        equ     040h    ; write to handle
DOS_TERMINATE           equ     04ch    ; terminate with error code

DOSINT macro function
        mov     ah,function
        int     21h                     ; invoke DOS function
endm

DOSINT2 macro function, subfunction
        mov     ax,(function SHL 8) OR (subfunction AND 0ffh)
        int     21h                     ; invoke DOS function
endm


.CODE


;****************************************************************************
;                                                                  showdate
;
; fetches the DOS system date, prints it to stdout and exits
; the format of the output is identical to that of the Posix ctime()
; function:
;
;      Thu May 11 16:11:30 2000
;
; The day of week and month are always 3 characters long.  The time of
; day is in 24hour form (e.g. 16:11:30 is a few minutes after four in
; the afternoon) and the year is always four digits.  The whole thing is
; followed by a newline character (line feed = 0ah), making 25
; characters total.
;
; Note that ctime() returns 26 characters which is all of the above,
; followed by a terminating NUL char but this program does not emit a
; NUL.)
;
; Entry:
;       DS points to segment for our data tables
;
; Exit:
;       carry may be set if last write failed
;
; Trashed:
;       none
;
;****************************************************************************
showdate proc
        pusha                   ;
        DOSINT  DOS_GET_DATE    ;
; returns the following
;       cx = year (1980-2099)
;       dh = month (1-12) == (Jan..Dec)
;       dl = day (1-31)
;       al = day of week (0-6) == (Sun..Sat)

        push    cx              ;
        push    dx              ; save the return values

        ; write the day of week
        mov     dx, offset dayname  ;
        call    WriteSubstring  ;

        ; write the month
        pop     ax              ; recall month/day
        push    ax              ; and save it again
        mov     al,ah           ; isolate just month
        dec     al              ; month starts at 1
        mov     dx, offset monthname; monthname array
        call    WriteSubstring  ;

        ; write the day of the month
        pop     ax              ;
        call    WriteNumber     ;
        call    WriteSpace      ;

        ; write the hour
        DOSINT  DOS_GET_TIME    ; ch = hour, cl = min,
                                ; dh = sec, dl = hundredths

        push    dx              ; save seconds
        push    cx              ; save minutes
        mov     al,ch           ;
        call    WriteNumber     ;
        call    WriteColon      ;

        ; write the minutes
        pop     ax              ;
        call    WriteNumber     ;
        call    WriteColon      ;

        ; write the seconds
        pop     ax              ;
        mov     al,ah           ;
        call    WriteNumber     ;
        call    WriteSpace      ;

        ; write the year (century first)
        pop     ax              ;
        xor     dx,dx           ; clear other reg before divide
        mov     cx,100          ; ax = ax/100, dx = remainder
        div     cx              ;
        push    dx              ; save remainder
        call    WriteNumber     ;

        ; write the year (year within century)
        pop     ax              ;
        call    WriteNumber     ;
        mov     dx,offset newlinechar
        call    PrintOne        ;
        popa                    ; restore stack
        ret                     ;
showdate endp

;****************************************************************************
;                                                            WriteSubstring
;
; writes a short substring to stdout
; specifically, prints CL characters, starting at DS:(DX+CL*AL)
;
; Entry:
;       DS:DX ==> pointer to base of string array
;       CL    =   size of each string
;       AL    =   string selector (i.e. which string)
;
; Exit:
;       CY set if there was an error writing last byte
;       if CY clear,
;               AX = 1 (number of bytes written)
;       else
;               AX = error code
;
; Trashed:
;       BX CX DX
;
;****************************************************************************
WriteSubstring proc
        xor     ah, ah
        add     ax, ax
        add     ax, ax
        add     dx,ax           ; offset now points to appropriate day string
        call    PrintIt         ;
WriteSubstring endp
        ; deliberately fall through
;****************************************************************************
;                                                                WriteSpace
;
; writes a single space character (20h) to stdout
;
; Entry:
;       DS points to data table segment
;
; Exit:
;       CY set if there was an error writing last byte
;       if CY clear,
;               AX = 1 (number of bytes written)
;       else
;               AX = error code
;
; Trashed:
;       BX CX DX
;
;****************************************************************************
WriteSpace proc
        mov     dx,offset spacechar;
WriteSpace endp
        ; deliberately fall through
;****************************************************************************
;                                                                  PrintOne
;
; prints a single character pointed to by DS:DX
;
; Entry:
;       DS:DX ==> points to the character to be printed
;
; Exit:
;       CY set if there was an error writing last byte
;       if CY clear,
;               AX = 1 (number of bytes written)
;       else
;               AX = error code
;
; Trashed:
;       BX CX DX
;
;****************************************************************************
PrintOne proc
PrintOne endp
        ; deliberately fall through
;****************************************************************************
;                                                                   PrintIt
;
; prints the passed string to stdout
;
; Entry:
;       DS:DX ==> points to string to be printed
;       CX    =   number of bytes to be printed
;
; Exit:
;       CY set if there was an error writing to stdout
;       if CY clear,
;               AX = number of bytes written
;       else
;               AX = error code
;
; Trashed:
;       none
;
;****************************************************************************
PrintIt proc
        mov     ah, 9       ;the print command 
        int     21h         ;print string
        ret                     ;
PrintIt endp

;****************************************************************************
;                                                                WriteColon
;
; writes a colon character to stdout
;
; Entry:
;       DS points to data segment
;
; Exit:
;       CY set if there was an error writing to stdout
;       if CY clear,
;               AX = 1 (number of bytes written)
;       else
;               AX = error code
;
; Trashed:
;       none
;
;****************************************************************************
WriteColon proc
        mov     dx,offset colonchar;
        jmp     PrintOne        ;
WriteColon endp

;****************************************************************************
;                                                               WriteNumber
;
; prints the number in AL to stdout as two decimal digits
;
; Entry:
;       AL      = number to be printed.  It must be in the range 00-99
;
; Exit:
;       CY set if there was an error writing to stdout
;       if CY clear,
;               AX = 2 (number of bytes written)
;       else
;               AX = error code
;
; Trashed:
;       BX CX DX
;
;****************************************************************************
WriteNumber proc
        xor     ah,ah           ; clear out high half
        mov     cl,10           ; prepare to convert to decimal (base 10)
        div     cl              ; divide it out
        or      ax,3030h        ; convert to ASCII digits
        push    ds              ; remember DS for later
        push    ax              ; push converted chars on stack
        mov     dx,ss           ;
        mov     ds,dx           ; ds = ss
        mov     dx,sp           ; print data from stack
        mov     cx,2            ; two characters only
        call    PrintIt         ;
        pop     bx              ; fix stack
        pop     ds              ; restore ds pointer
        ret                     ;
WriteNumber endp

;.DATA
        dayname         db "Sun$Mon$Tue$Wed$Thu$Fri$Sat$"
        monthname       db "Jan$Feb$Mar$Apr$May$Jun$Jul$Aug$Sep$Oct$Nov$Dec$"
        spacechar       db " $"
        colonchar       db ":$"
        newlinechar     db 10, 13, '$'   ; in C this is \n

end

21

#fasm#
;Version with extended syntax (fasm)
;Display number in binary, shift and carry

        org  100h

;Decimal to hexadecimal display

        org 100h            ;Start address


        xor ah, ah          ;we want to read bytes
        xor bx, bx          ; bx will store the total
        mov si, 0x82
        mov cl, [0x80]      ;size in bytes of command line
        dec cl
        jle finished        ;no digits present
nextdigit:
        lodsb               ;read character
        sub al, '0'         ;get the digit
        jl  finished        ;end of number
        push ax             ;need to multiply exisitng value by 10
        mov ax, bx          ;mul only works on ax
        mov dx, 10          ;multiply by 10
        mul dx              ;ax = bx * 10
        mov bx, ax          ;bx is shifted
        pop ax              ;restore the character
        add bx, ax          ;add to the total
        loop nextdigit      ;whilst there are more digits

finished:
        mov ax, bx          ;we want to display bx
        call print_ax_bin   ;value is in ax

        ret

print_ax_bin:
        push ax             ;save registers that will be modified
        push bx
        mov bx, ax          ;we want each bit, so copy to bx
        mov ah, 0eh         ;needed for output character
        repeat 16           ;unrolled as a test only
            shl bx, 1       ;get top bit into carry
            mov al, '0'     
            adc al, 0       ;al = '0', or '1' if carry set
            int 10h         ;output character
        end repeat
        pop bx
        pop ax              ;restore all registers
        ret

Here is a sample of a Assembly assignment, compare our solutions to any others. Check out our Assembly programming homework help.

ARM assembly language

The ARM microprocessor is an example of a RISC processor, which stands for Reduced Instruction Set Computer. It is a 32 bit processor, and used in the Nintendo Gameboy Advance (and the 3DS as well), mobile phones, and some tablets. It operates in 2 different modes, ARM mode (which uses 32 bit instructions) and THUMB mode which uses 16 bit instructions. Almost every instruction can be executed conditionally, which can make it very efficient. For example in a conventional processor to write an abs function, you would do if (a < 0) a = -a; this converts into TEST A; BGE SKIP; NEG A in a conventional processor but the ARM could use TEST A; NEGLT A so the code is not only smaller but also is easier to pipeline.

Problem:

Write an ARM assembly function that takes an array of integers and returns the index of the first occurrence of the integer in the array if it exists or -1 if it does not. Remember the initial integer in the array is at index zero.

The C language program is:

#include <stdio.h>

extern intintfind( int array[], intlookfor, int size ) ;

void main( intargc, char * argv[] )
{
    intnumarray[] = { 113, 114, 252, 280, 332 };
    intlookfor = 252 ;
    int size = sizeof(numarray)/sizeof(int) ;
    int result ;

    result = intfind( numarray,  lookfor, size ) ;
    printf( "Integer  appears at %d\n", result ) ;

}

The input to the ARM assembly language function is a pointer to the first element of the array in register a1. The integer to look for is in a2 The size of the array is in a3 and is the number of integers. Remember an integer is 4 bytes long.

.global intfind
    .type   intfind, %function
intfind:
    @ save the frame base(fp) of previous function
    @ set the new frame base to the stack pointer(sp)
str fp, [sp, #-4]!
    add fp, sp, #0
    @ put the parameters r0 (array), r1 (lookfor), r2 (size) on to stack, so we can reuse these registers.
    sub sp, sp, #28
    str r0, [fp, #-16]
    str r1, [fp, #-20]
    str r2, [fp, #-24]

    @ put i (initialized to 0) to the stack
    @ so far we have stack state: -16 for array, -20 for lookfor, -24 for size, -8 for i.
    mov r3, #0
    str r3, [fp, #-8]
    b   .L5
.L7:
    @ consider the next element, i = i + 1, save the new i onto the stack
    ldr r3, [fp, #-8]
    add r3, r3, #1
    str r3, [fp, #-8]
.L5:
    @ load i and size from stack into r2 and r3, respectively.
    ldr r2, [fp, #-8]
    ldr r3, [fp, #-24]
    @ if i >= size, jump to .L6, which will return 
    cmp r2, r3
    bge .L6
    @ otherwise, load i into r3, and array starting address into r2
    ldr r3, [fp, #-8]
    mov r3, r3, asl #2
    ldr r2, [fp, #-16]
    @ r3 = r2 + r3, so r3 has the address of the i-th element in the array
    add r3, r2, r3
    @ load array[i] into r2
    ldr r2, [r3, #0]




    @ loadlookfor into r3
    ldr r3, [fp, #-20]
    @ if array[i] is not lookfor, jump to .L6, where the next element is considered.
    cmp r2, r3
    bne .L7
.L6:
    @ load i into r2, load size into r3
    ldr r2, [fp, #-8]
    ldr r3, [fp, #-24]
    @ if i >= size, which means there is no lookfor in the array, jump to .L8 where r2 is set to -1
    cmp r2, r3
    bge .L8
    @ otherwise i is the position of lookup in the array
    b   .L9
.L8:
    @ set r2 to -1
    mvn r2, #0
.L9:
    @ r2 is the return value, move it to r0 (return value of function call)
    mov r0, r2
    @ recover the stack pointer and frame pointer
    add sp, fp, #0
    ldmfd   sp!, {fp}

    @ return from this function
    bx  lr
    .size   intfind, .-intfind

This is a Assembly assignment, you can see the nature of the solutions. So if you need help with Assembly project or just need a Assembly online tutor to help you, we can do that.

MIPS Assembly language

The MIPS processor is another RISC processor, which was used in the Playstation console amongst others. It has a large complement of registers, with register 0 being a special case, it’s value is always 0, so to negate a value you would subtract the register from the $0 register. There are 2 different emulators used in MIPS development, SPIM and MARS, they have slightly different syntax so you need to make sure you specify which version you require. One particularly complex assignment I did was Sudoku in MIPS assembly
language, it could solve most puzzles.

Write a correct program in MIPS – SPIM assembly language that:
1) Reads Roman Numerals as ASCII text characters.
2) Calculates the equivalent decimal value.
3) Writes the calculated value as Arabic Numerals to the SPIM
display screen with the appropriate commentary text.
4) Test your program by calculating the values of each of these seven
Roman Numerals:
I V X L C D M
5) Calculate the value, and display the result of these Roman Numerals:
XXIX
MMXIV
MCMXLVIII

You need to let the user know whether the input must be Upper case or lower case. You do not need to check for “valid” Roman numbers, but you do need to calculate a consistent decimal value. For example, while VIIII is not considered “valid”, you should none the less calculate the value as 9.

Use the System Service calls on page A-44 for the input and output.

The work products of this assignment are:
1) A copy of the source program.
2) Screen captures showing the output results.

.data

.align 2
welcome: .asciiz "Enter a Roman numeral that contains IVXLCDM.\nLowercases and invalid letters will be ignored. \n"
# assume the roman has at most 32 characters
roman  : .space 32

.text

.globl main

main:
    # ask the user to input the roman numeral
    li $v0, 4       # print welcome
    la $a0, welcome
    syscall
    li $v0, 8       # read string, save into roman
    la $a0, roman
    li $a1, 32
    syscall

    la $a0, roman
    jal calculate_recursive

    # display the result
    move $s0, $v0
    li $v0, 1
    move $a0, $s0
    syscall

    # terminate the system
    li $v0, 10
    syscall

# a recursive function to convert roman to decimal
# the beginning address of the roman is passed in $a0
# the result decimal is saved into $v0
calculate_recursive:
    sw $s0, 8($sp)
    sw $a0, 4($sp)
    sw $ra, 0($sp)     # save the return address and parameter
    addi $sp, $sp, -12

    li $s0, 0 # initialize return value to 0

    # now load the first character in $a0
    lb $t0, 0($a0)       # t0 = the first character
    li $t2, 10
    beq $t0, $t2, ret    # t0 == '\n', end of the string
    beq $t0, $zero, ret  # t0 == '\0', end of the string
    lb $t1, 1($a0)       # t1 = the next character

# check I(73) IV(73 86) IX(73 88)
sI: # 
    li $t2, 73       # t2 = 73 (I)
    bne $t0, $t2, sX # t0 != I, check X
IV:
    # otherwise, check whether the following is V
    li $t2, 86        # V
    bne $t1, $t2, IX  # next (t1) != V 
    # IV
    addi $t3, $a0, 2  # the new address of recursive call is $t3 = $a0 + 2
    li $s0, 4         # the return value is 4
    j recursive       # recursive call with $t3 as the new starting address

IX:
    li $t2, 88        # X
    bne $t1, $t2, I   # next (t1) != X
    # IX
    addi $t3, $a0, 2  # the new address of recursive call is $t3 = $a0 + 2
    li $s0, 9         # the return value is 9
    j recursive       # recursive call with $t3 as the new starting address

I:
    # thus, this is a single I, its value is 1
    addi $t3, $a0, 1  # the new address of recursive call is $t3 = $a0 + 1
    li $s0, 1         # the return value is 9
    j recursive       # recursive call with $t3 as the new starting address


# check X(88) XL(88 76) XC(88 67)
sX:
    li $t2, 88       # t2 = 88 (X)
    bne $t0, $t2, sC # t0 != X, check C
XL:
    # otherwise, check whether the following is L
    li $t2, 76        # L
    bne $t1, $t2, XC  # next (t1) != L
    # XL
    addi $t3, $a0, 2  # the new address of recursive call is $t3 = $a0 + 2
    li $s0, 40        # the return value is 40
    j recursive       # recursive call with $t3 as the new starting address

XC:
    # otherwise, check whether the following is C
    li $t2, 67        # C
    bne $t1, $t2, X   # next (t1) != C
    # XC
    addi $t3, $a0, 2  # the new address of recursive call is $t3 = $a0 + 2
    li $s0, 90        # the return value is 90
    j recursive       # recursive call with $t3 as the new starting address

X:
    # thus, this is a single X, its value is 10
    addi $t3, $a0, 1  # the new address of recursive call is $t3 = $a0 + 1
    li $s0, 10        # the return value is 10
    j recursive       # recursive call with $t3 as the new starting address

# check C(67) CD(67 68) CM(67 77)
sC:
    li $t2, 67       # t2 = C
    bne $t0, $t2, sV # t0 != C, check V
CD:
    # otherwise, check whether the following is D
    li $t2, 68        # D
    bne $t1, $t2, CM  # next (t1) != D
    # CD
    addi $t3, $a0, 2  # the new address of recursive call is $t3 = $a0 + 2
    li $s0, 400       # the return value is 400
    j recursive       # recursive call with $t3 as the new starting address

CM:
    # otherwise, check whether the following is M
    li $t2, 77        # M
    bne $t1, $t2, C   # next (t1) != M
    # CM
    addi $t3, $a0, 2  # the new address of recursive call is $t3 = $a0 + 2
    li $s0, 900       # the return value is 900
    j recursive       # recursive call with $t3 as the new starting address

C:
    # thus, this is a single C, its value is 100
    addi $t3, $a0, 1  # the new address of recursive call is $t3 = $a0 + 1
    li $s0, 100       # the return value is 10
    j recursive       # recursive call with $t3 as the new starting address

sV: # 86
    li $t2, 86
    bne $t0, $t2, sL  # t0 != V, check L
    addi $t3, $a0, 1  # the new address of recursive call is $t3 = $a0 + 1
    li $s0, 5         # the return value is 5
    j recursive       # recursive call with $t3 as the new starting address

sL: # 76
    li $t2, 76
    bne $t0, $t2, sD  # t0 != L, check D
    addi $t3, $a0, 1  # the new address of recursive call is $t3 = $a0 + 1
    li $s0, 50        # the return value is 50
    j recursive       # recursive call with $t3 as the new starting address

sD: # 68
    li $t2, 68
    bne $t0, $t2, sM  # t0 != D, check M
    addi $t3, $a0, 1  # the new address of recursive call is $t3 = $a0 + 1
    li $s0, 500       # the return value is 5
    j recursive       # recursive call with $t3 as the new starting address

sM: # 77
    li $t2, 77
    bne $t0, $t2, sU  # t0 != M, unknown
    addi $t3, $a0, 1  # the new address of recursive call is $t3 = $a0 + 1
    li $s0, 1000      # the return value is 1000
    j recursive       # recursive call with $t3 as the new starting address

sU:
    addi $t3, $a0, 1  # the new address of recursive call is $t3 = $a0 + 1
    li $s0, 0         # the return value is 0. thus this  unknown character is ignored
    j recursive       # recursive call with $t3 as the new starting address

recursive:
    move $a0, $t3     # recursive with the new address
    jal calculate_recursive
    add $s0, $s0, $v0 # accumulate the new value

ret:
    move $v0, $s0
    addi $sp, $sp, 12  # recover the return address and return
    lw $ra, 0($sp)
    lw $a0, 4($sp)
    lw $s0, 8($sp)
    jal $ra

If you need a Assembly tutor to tutor you on Assembly programming assignments like this, you’re welcome to feel free to} Contact us.

 They have their own set of instructions called ‘machine language instructions’, that handle various operations like getting input from keyboard, on screen information displaying and performing various other jobs. Students who seek help with assembly programming homework can upload their assembly programming assignment on our website or they can email us as well.

A processor understands only machine language instructions, in the form of 1’s and 0’s.Themachine language is difficult to understand and to implement. So, the low-level assembly language is designed for specific families of processors that represent various instructions in symbolic code in a more understandable form. By taking our help with assembly programming assignment, it is easier for the students to understand the machine language.

 They have their own set of instructions called ‘machine language instructions’, that handle various operations like getting input from keyboard, on screen information displaying and performing various other jobs. Students who seek help with assembly programming homework can upload their assembly programming assignment on our website or they can email us as well.

A processor understands only machine language instructions, in the form of 1’s and 0’s.Themachine language is difficult to understand and to implement. So, the low-level assembly language is designed for specific families of processors that represent various instructions in symbolic code in a more understandable form. By taking our help with assembly programming assignment, it is easier for the students to understand the machine language.

Other processors

6502, Z80 Assembly language

I’ve not done any assignments in these languages, but I have published games in them, so I can complete any assignments you may have. Both of these are 8 bit processors, and are limited to 64K of memory (unless you have external hardware that pages the memory). The 6502 only has 3 registers, A, X, Y. The A register is used to load and store to memory and to perform any arithmetic instructions. The X & Y registers are used to index memory. The first 256 locations are known as page 0 and are used as quick access variables and to construct pointers to
access memory indirectly. The next 256 locations act as the stack. The Z80 has more registers than the 6502, including register pairs such as BC, DE, HL which can act as a 16 bit register. It also has IX, IY which are used to provide indexed access to memory.

LC3 Assembly language

The LC3 assembly language is an artificial assembly language used for teaching. It has a very limited set of instructions.

68000 Assembly language

This is the processor where I have the greatest experience, I’ve done a few assignments in it, but also published around 10 games. It is a 16 bit processor (when accessing memory, although the registers are 32 bits in size). It was used on Atari ST, Commodore Amiga, Apple Mac and
was a popular alternative to the Intel processors. There were 8 data registers, D0-D7 and 8 address registers, A0-A7.

SPARC Assembly language

Another processor that is mainly used in courses now, but it was part of the SPARC workstations, which were a popular graphics machine for 3D modelling. Most courses use ISEM (Instructional Sparc Emulator) to run the code.

Microcontrollers

There are a few different processors used in embedded systems programming such as the Arduino. Many microcontroller assignments may involve C code instead of assembly, but I can do both.

Our expert assembly language tutors also explain the several advantages of assembly language programming such as, it requires less memory and less time to execute, easily allows hardware-specific complex jobs, is suitable for time-critical jobs and is most suitable for other memory resident programs and writing interrupt service routines. The hardware of a computer consists of processor, memory, and registers. The executions of assembly language program is in such a way that the system copies the code into the internal memory from the external device. The program instructions are then executed by the processor. We are already getting some rave reviews for our assembly programming project help. We also offer online assembly programming assignment for students as well as working professionals. Students from across the world have availed our help with assembly programming assignment.

The memory segment model divides the memory system into groups of independent segments that identifies the location is in the segment register and are referenced by the pointers. Each segment is used to contain a specific type of data. The segments in which the instruction codes are present in one segment, the data elements stored in another segment, and a third segment keeps the program stack.

Applications of Assembly Programming Language

Assembly programming language is still offered in most colleges and universities because it is the only logical way to learn fundamental behaviors of computers. It is vital to grasp how the computer operates at the hardware level. Our premier assembly language programming homework help is a convenient platform to learn the basic concepts, learn appropriate situations where assembly language might be used and recognize how efficient executable codes can be created from high-level languages. Our experts outline the following as the typical applications of assembly language:

  • Reverse engineering – Interactive Disassembler tool is used extensively to crack commercial software by competing companies to produce a software with similar results. This technique is used to translate machine code to higher-level language.
  • Debugging and optimization purposes – There are some compilers which translate high-level languages into assembly first before compilation. Assembly language can therefore be used for debugging and optimization purposes.
  • System’s boot code – Assembly language is used to write the low-level code that tests the hardware of a computer before the operating system is booted.
  • Computers with limited processing power and RAM require assembly language to enhance their speed of execution.

Why ProgrammingHomeworkHelp.com is the most trusted and reliable assembly language assignment help provider

It is not just anybody who can provide you with assembly language project help. You need a site with a proven track record of performance. However, this is not easy to find because most sites are in this domain to make money. We are glad to tell you that we are different. If you want a site that you can trust with your academic papers then it is us. We have immense experience in assisting students with their assembly language assignment by providing them with quality solutions.

The experts who will assist you on our site are very proficient and very knowledgeable in programming. They will handle all your intricate assignments with ease and relieve you from all the stress. Our mission is to see you score the grades you desire in your coursework and our experts are committed to this course. That is why they do a thorough research on your work before sending it to you.

Struggling in your assignments will be history if you avail our service. Our experts will provide you with a step-by-step guidance to help you learn all the concepts. Our main aim is to ensure you notice a massive improvement in your grades after getting help from us. We have helped many students across the world and our experts can definitely help you too. So contact us now and let us help you impress your professor with our top-notch content.

You can sign up for our service regardless of where you are located. We offer assistance to students in countries like the USA, UK, Canada, Malaysia, Singapore, Australia and many more. So feel free to get in touch with us. Your satisfaction is of great value to us. We are available both during the day and at night to handle all your queries. You can visit our site at any time and get your assembly language homework solved. Our customer support team is also available round the clock. They can help you place your order or clear all the doubts in your mind. You just need to send them an email or chat with them.

How to request for our service

Forget the many bureaucratic procedures that some sites want you to follow. Placing an order with us is very simple. All you have to do is to follow the steps below

  1. Send us your assignment and the guidelines to be followed – fill in the form on our homepage with your details and attach your assignment with it.
  2. Receive a quote from us – We will come up with the amount you are supposed to pay and send it to you via email.
  3. Make your Payment – You can make your payment through PayPal or any international debit/credit card
  4. Sit back and relax as we work on your assignment and deliver it on time – Our experts will work on your assignment and deliver impeccable solutions. You can log in at any time and check the status of your assignment via our assignment tracker facility.

What you stand to gain if you get help from us

  • Exemplary performance in your coursework – In the long run, it is the grades that will determine whether you graduate with honors or not. No other site can guarantee you better grades that us. We want only the best for our clients. Our experts only deliver accurate and precise solutions that will make your professor award you top grades. We will not just provide you with quality solutions but also help you with the concepts you are weak at. Our experts will provide you with detailed and self-explanatory solutions that you can easily understand. The content will improve your knowledge and help you solve the same question in future. We also have on our site sample assignments and projects we have done for our clients. You can use them for your revision and practice.
  • We help you beat all your deadlines by delivering your work on time – Most students are always frustrated by their deadlines. This is because there are so many tasks allotted in school/ college and each task has a timeframe. Students must therefore study and do research till late to be able to complete all the assigned tasks. Getting help from our experts make everything easy. You will not have to worry about your assignments because our experts will be handling them for you. All you have to do is to wait for the mutually agreed time and receive exceptional solutions from us. Our service also gives you ample time to do other useful activities which were being hindered by your heavy assignment workload.
  • You will receive top quality solutions from us – Only a well-written content can only attract top grades. Our experts will do everything possible to refine your content and ensure it meets the standards required by your professor. We check and proofread all the solutions we provide before submitting them to our clients. You can be rest assured that the solutions you will get are not erroneous. We pay attention to all your request and will follow all your requirements.
  • The content you will receive has not been presented anywhere else and is uniquely drafted to suit your requirements – Our work is 100% original and has not been copied. We put strict emphasis in dealing with plagiarism. We use “Turnitin” software to eliminate all forms of plagiarism. If we use information from some sources then we will cite them as required.
  • You can request for a rework on your assignment and we will do it for free – Send us an email with the details of your rework request and our experts will gladly do it to your satisfaction. The request must be in-line with your guidelines. In case you need a refund then please refer to our refund policy.
  • Competitive rates that are tailor-made for students – Our service is cheaper compared to other sites. We offer favorable rates no matter how complex the task is. We give you full value of your money by providing you with exceptional solutions at a very fair rate. Thousands of students use our service consistently because of this. They also refer their classmates and friends to us because they know we are the best. If you are a repeat user of our service, we can offer you great discounts.

So be a part of this amazing service and enjoy the awesome benefits. You only need to type “do my assembly language homework” on our site and we will get back to you immediately. We are assignment writer specialists. Try us today and notice the difference. You will definitely come back for more because we never disappoint.