Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [BITS 16]
- [ORG 0x7C00]
- ;Program that uses loops to print out a square as well as student details and favourite movie.
- top:
- ;; Put 0 into ds (data segment)
- ;; Can't do it directly
- mov ax,0x0000
- mov ds,ax
- ;; si is the location relative to the data segment of the
- ;; string/char to display
- ;Moves 0 into the dx register to act as the counter for the outer loop
- mov dx, 0
- outerLoop:
- mov cx, 6 ; Moves 6 into the cx register.
- loop: ;Loop label
- mov si, dotVariable ;Moves the dot variable into the si register.
- call writeString ; Calls the write string function which keeps executing by printing out a dot until the counter reaches 0.
- dec cx ;Decrements the cd regist
- cmp cx, 0 ;Compares the contents of the cx register and checks whether its contents are equal to 0.
- jge loop ;If the value in the cx register is greater than 0 jump to the loop label and execute the above procedure until cx is equal to 0 .
- mov si, spaceVariable ;Moves the spaceVariable into the si register which serves the purpose of adding a new line since the dotVariable has 0,10,0 which indicates a new line.
- call writeString ; Calls the writeString function with the space variable effectively creating a new line.
- inc dx ; ;Increments the dx register by one.
- cmp dx, 6 ;Compares the contents of the dx register with 6 each time the loop runs.
- jle outerLoop ; If the value of dx is less than or equal to 6 it jumps to the outer looop;
- mov si, studentName ;Moves the studentName variable to si register
- call writeString ;Prints each character at a time until it encounters a null character at which point the process is repeated until no more strings remain in the buffer.
- mov si, studentCourse ;Repeats the same procedures mentioned above.
- call writeString
- mov si, favouriteMovie
- call writeString
- jmp $ ; Spin
- writeString:
- mov ah,0x0E ; Display a chacter (as before)
- mov bh,0x00
- mov bl,0x07
- nextchar:
- Lodsb ; Loads [SI] into AL and increases SI by one
- ;; Effectively "pumps" the string through AL
- cmp al,0 ; End of the string?
- jz done
- int 0x10 ; BIOS interrupt
- jmp nextchar
- done:
- ret
- ;User defined variables.
- spaceVariable db 13,10,0 ;Null - terminated
- dotVariable db '.' ,0,10,0 ;Null - terminated
- studentName db 'Name: Martin Vasilev' ,13,10,0 ;Null -terminated
- studentCourse db 'Course: Computer Science' ,13,10,0 ;Null - terminated
- favouriteMovie db 'Favourite Movie: Ex Machina' ,13,10,0 ;Null -terminated
- times 510-($-$$) db 0
- dw 0xAA55
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement