Saturday 22 February 2020

Week 6 - Lab 4 continued and Lecture

This week's lab also we were supposed to work on Lab 4 and I will talk about the second task that were supposed to work on, in this blog. Now in case you guys did not check out last post this was our task:

Option 2: Data Input Form[edit]

  1. Create a subroutine which enables the user to enter a string of up to 40 characters. Decide how the data will be returned from the subroutine. The user should be able to use the left/right cursor keys and backspace to edit the text, and the cursor location should be visible to the user.
  2. Write a program which uses this subroutine to collect the user's name, address, city, province, and postal code, and then display this information formatted as a shipping address (for example, as shown below).


Your order will be delivered to: J. Doe 1750 Finch Ave E Toronto ON M2J 2X5

Now the approach used was to store each of the inputs was that each iteration would give a message (stored as constant byte) followed by the user input (stored as empty dcb's of required lengths). Then each of the empty constant bytes will be replaced by user input accordingly and displayed in the last iteration with the help of labels. Now there was a very important concept about logical operations we were taught in week 5 which was XOR or EOR which stands for exclusive OR. Anything EOR with 0 would keep the original value and EOR with 1 would give a flipped value. So basically we used it to flip the bits.
Here is code for lab 4 task 2:

define        SCINIT        $ff81 ; initialize/clear screen
define        CHRIN        $ffcf ; input character from keyboard
define        CHROUT        $ffd2 ; output character to screen
define        SCREEN        $ffed ; get screen size
define        PLOT        $fff0 ; get/set cursor coordinates
define    POINTER        $10    ; ptr: start of row
define    POINTER_H    $11
define    SPOINTER    $12    ; ptr: start of screen
define    SPOINTER_H    $13
define MAX_INPUT    $14


    lda #$f0
    sta SPOINTER_H
    lda #40
    sta MAX_INPUT
   
          jsr SCINIT

; Name
          ldx #<label1    ; loading X with a pointer to the string to be printed
          ldy #>label1    ; loading Y with a pointer to the string to be printed
      jsr prtstr    ;  print string

          ldx #<name    ; loading X with a pointer to the string to be read and store
          ldy #>name
          lda #len1 ; length of string

          jsr getstr    ; go get user input

          jsr SCINIT

;Address

          ldx #<label2
          ldy #>label2
          jsr prtstr

          ldx #<address    ; loading X with a pointer to the string to be read and stored
          ldy #>address    ; loading X with a pointer to the string to be read and stored
          lda #len2 ; length of string

          jsr getstr    ;  get user input

          jsr SCINIT

;City

          ldx #<label3
          ldy #>label3
          jsr prtstr

          ldx #<city    ; loading X with a pointer to the string to be read and stored
          ldy #>city    ; loading Y with a pointer to the string to be read and stored
          lda #len3 ; length of string

          jsr getstr    ; go get user input

          jsr SCINIT

; Printing final message and captured details

          ldx #<label4    ; load XY with a pointer to the string to be printed
          ldy #>label4
      jsr prtstr    ; go print string

          ldx #<name    ; load XY with a pointer to the string to be printed
          ldy #>name
      jsr prtstr    ; go print string

      jsr prtcrlf

          ldx #<address    ; load XY with a pointer to the string to be printed
          ldy #>address
      jsr prtstr    ; go print string

      jsr prtcrlf

          ldx #<city    ; load XY with a pointer to the string to be printed
          ldy #>city
      jsr prtstr    ; go print string

      jsr prtcrlf
         
          brk

prtcrlf:               ;this subroutine moves the code to a newline
      ldx #<crlf    ; there is only one parameter 
      ldy #>crlf    ;prints a newline carriage return character
      jsr prtstr


prtstr:                                  ; this subroutine prints a NULL terminated string
          stx POINTER           ; there is only one parameter
          sty POINTER_H      ;    registers XY point to the string to be printed

          ldy #$00         

prtchar:    
          lda (POINTER),y
          beq prtstrdone

          jsr CHROUT

          iny
          bne prtchar

prtstrdone:
          rts


getstr:                       ;this subroutine takes care of the typing and checking of keys
 stx POINTER           ; there is 2 parameters the pointer and length of string
         sty POINTER_H
    sta SPOINTER
    ldy    #$00
   
check2:
idle:     inx
          cpx #$10
          bne check
          lda (SPOINTER),y
          eor #$80
          sta (SPOINTER),y
check:    lda $ff
          beq idle

          ldx #$00
          stx $ff

          cmp #$08
          bne print

          lda (SPOINTER),y
          and #$7f
          sta (SPOINTER),y

          dey
          jmp next

print: 
    cpy MAX_INPUT
    beq maxed

     cmp #$0D    ; check for Enter key
     beq done

     cmp #$83    ; check for Left arrow key  
     beq go_left

     cmp #$81    ; check for Right arrow key
     beq go_right

    sta (SPOINTER),y
    sta (POINTER),y
          iny

maxed: 
          jmp check2

go_left:
;brk
    dey
    cpy #$ff
    bne not_at_left

    iny

not_at_left:
    jmp idle

go_right:
;brk
    lda (POINTER),y
    cmp #$00
;brk
    beq not_at_right

    iny

not_at_right:
    jmp idle

done: 
 rts

label1:
dcb "p","l","e","a","s","e",32,"e","n","t","e","r",32,"y","o","u","r",32,"n","a","m","e",":",00
define len1 24

label2:
dcb "p","l","e","a","s","e",32,"e","n","t","e","r",32,"y","o","u","r",32,"a","d","d","r","e","s","s",":",00
define len2 27

label3:
dcb "p","l","e","a","s","e",32,"e","n","t","e","r",32,"y","o","u","r",32,"c","i","t","y",32,"a","n","d",32,"p","o","s","t","a","l",32,"c","o","d","e",":",00
define len3 40

label4:
dcb "Y","o","u","r",32,"o","r","d","e","r",32,"w","i","l","l",32,"b","e",32,"d","e","l","i","v","e","r","e","d",32,"t","o",":",$0d,$0d,00

name:
dcb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,$0d

address:
dcb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,$0d

city:
dcb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,$0d

crlf:
dcb $0d,0

So by incorporating previous task's knowledge about working with character display and some additional information we were able to finish this lab.

Lecture:
This week's lecture started with a quiz and it was all about differences between the architecture we already finished learning and the architectures we were in process of learning i.e. 6502, AArch 64 and X86 64. And after the quiz the prof. gave us a summary about the 3.
6502: 8 bit processor, 16 bit address, 3 registers.
X86 64: 64 bit processor, 64 bit address, 16 registers.
AArch 64: 64 bit processor, 64 bit address, 31 registers.

Then we got an insight on how both architectures started from different approaches i.e. RISC (have tiny instructions but small and fast), and CISC (complex instructions) and ended up curving in a way to come on similar grounds. 

Then we were shown a sample hello world program that had some weird looking syntax at first but then made sense once we got to understand it.
Overall we knew we were taking a step forward into the this assembly language and had to be ready for it.

No comments:

Post a Comment