Advertisement
vasilev5

Untitled

Feb 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [BITS 16]
  2. [ORG 0x7C00]
  3.  
  4. ;Program that uses loops to print out a square as well as student details and favourite movie.
  5.  
  6.  
  7. top:
  8.     ;; Put 0 into ds (data segment)
  9.     ;; Can't do it directly
  10.     mov ax,0x0000
  11.     mov ds,ax
  12.     ;; si is the location relative to the data segment of the
  13.     ;; string/char to display
  14.  
  15.  
  16.  
  17.  
  18.     ;Moves 0 into the dx register to act as the counter for the outer loop
  19.     mov dx, 0
  20.  
  21.  
  22. outerLoop:
  23.     mov cx, 6 ; Moves 6 into the cx register.
  24.         loop: ;Loop label
  25.     mov si, dotVariable ;Moves the dot variable into the si register.
  26.     call writeString ; Calls the write string function which keeps executing by printing out a dot until the counter reaches 0.
  27.     dec cx ;Decrements the cd regist
  28.     cmp cx, 0 ;Compares the contents of the cx register and checks whether its contents are equal to 0.
  29.     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 .
  30.     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.
  31.     call writeString ; Calls the writeString function with the space variable effectively creating a new line.
  32.     inc dx ; ;Increments the dx register by one.
  33.     cmp dx, 6 ;Compares the contents of the dx register with 6 each time the loop runs.
  34.     jle outerLoop ; If the value of dx is less than or equal to 6 it jumps to the outer looop;
  35.  
  36.    
  37.     mov si, studentName ;Moves the studentName variable to si register
  38.     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.
  39.     mov si, studentCourse ;Repeats the same procedures mentioned above.
  40.     call writeString
  41.     mov si, favouriteMovie
  42.     call writeString
  43.    
  44.    
  45.  
  46.     jmp $ ; Spin
  47. writeString:
  48.     mov ah,0x0E ; Display a chacter (as before)
  49.     mov bh,0x00
  50.     mov bl,0x07
  51. nextchar:
  52.     Lodsb ; Loads [SI] into AL and increases SI by one
  53.     ;; Effectively "pumps" the string through AL
  54.     cmp al,0 ; End of the string?
  55.     jz done
  56.     int 0x10 ; BIOS interrupt
  57.     jmp nextchar
  58. done:
  59.     ret
  60.    
  61.     ;User defined variables.
  62.     spaceVariable db  13,10,0 ;Null - terminated
  63.     dotVariable db '.' ,0,10,0 ;Null - terminated
  64.     studentName db 'Name: Martin Vasilev' ,13,10,0 ;Null -terminated
  65.     studentCourse db 'Course: Computer Science' ,13,10,0 ;Null - terminated
  66.     favouriteMovie db 'Favourite Movie: Ex Machina' ,13,10,0 ;Null -terminated
  67.  
  68.      
  69.     times 510-($-$$) db 0
  70.     dw 0xAA55
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement