// Learning Experience G
// Starter Code
//
// The on-line assembler is experimental and minimal.
// No guarantees are made about its correctness.
//
// Add your header comments (name, date, etc.) here.
// Name: Your Name
// Date: The date you started
// Version: Version with Date and Name
// CODE START
// DO NOT CHANGE THE SEGMENT OF CODE FROM HERE TO THE COMMENT "CHANGE HERE
and beyond" BELOW.
//*************************************
ldi r0, 4
shl r0, r0
shl r0, r0
jmp r0
// The following set of load instructions read the final values of the variables in
// memory locations into r1-r5 so that we can see them on the LEDs.
// Your code must jump to this point after it has stored the results in data memory.
// You should jump to location 4.
// ************address 0x04************
ldi r0, 0
ld r1, r0 //r1<-M[0x00] (array location)
inc r0, r0
ld r2, r0 //r2<-M[0x01] (account number length)
inc r0, r0
ld r3, r0 //r3<-M[0x02] (ID)
inc r0, r0
ld r4, r0 //r4<-M[0x03] (validity indicator)
inc r0, r0
ld r5, r0 //r5<-M[0x04] (checksum)
// Now loop forever
ldi r0, 0
// The address of this brz is the one used in validation: Address 0x0F.
brz r0, 0 //PC=0x0F
// You are permitted to add code after this point
// CHANGE HERE and beyond
// Your last instruction should be a jump to location 4
// in order to read the variables into registers r1-r5.
// ************address 0x10************
ldi r0, 4
jmp r0
// This is the pseudo code but I have no clue what I am supposed to do. We are using basic MOVA, INC, ADD, SUB, DEC, AND, OR, XOR, NOT, MOVB, SHR, SHL, LDI, ADI, LD, ST, BRZ, BRN, JMP. If you can do following the code I would very much appreciate it
// These products terms are then summed to form a checksum, If the resulting sum is a multiple of ten, it is a valid number (You may wish to try this with your credit card number.)
// Here is an example using a 7-digit account number, 4738514
// A valid account number should be indicated by writing Ox02 to data memory location Ox03; an invalid account number should be indicated by writing Ox08 to location Ox03. After your program has run to completion, it should jump to the prewritten validation portion of the program that loads these values back from memory into registers R1 to R4 (See Table 2.2), You must make certain that you do not impede your program from jumping back to the validation sequence, You must edit the starter code provided rather than starting a new file. Memory locations Ox03 through Ox1F can be used for temporary values used in the calculation, so long as data memory addresses Ox0-0x4 contain the correct information at the end of the program. You should use subroutines wherever possible to perform repeated functions. For example, you may write a "calculate checksum" subroutine that takes the account number as input and returns the checksum.
// Table 1.3: Luhn algorithm example using a 7-digit account number
// Step Original Digit Weighted by 1 or 2 Adjust to less than 10 Checksum
// 7x2=14 3x1=3 8x2=16 5x1=5 1x2=2 1495 169=7 4 + 5 + 3 + 7 + 5 + 2 + 4 = 30, which is a multiple of 10
// ix1=4
// 4x1-4
// Therefore 4738514 is a valid account number. Using the same method, you will find that 4738541 is not.
// Program Design Write an assembly language program that will first store the BCD code for the last four digits of your ID number to data memory, then validate an account number stored in data memory using the Luhn algorithm. Your program must write the BCD code for the last four digits of your ID number to memory location Ox02. For example, if the last four digits of your ID are 1234, the value Ob0001001000110100 (this is the same as Ox1234) should be stored in memory location 0x02. This must be performed during execution of your program, not prior to execution. The input data array will be stored in data memory prior to execution. The location and length of the data array are variable. Your program must read the address of the start of the array (i.e., a pointer to the array) and the length of the array from data memory. Data memory location 0x00 contains the pointer M, which indicates the memory address of the first element of the data array. You can assume that M will be a value between Ox20 and Ox30. This value will be stored in memory location Ox00 prior to execution. You must write your code so that it can perform the operations described in the specification starting at any address specified by the contents of data memory address Ox00.
// 2.1 Required Memory Locations Your program must follow the data memory requirements in Table 2.2 for variables that will be used during execution. The data.txt used for validation will be set up according to these requirements and your program will not validate correctly if you do not follow them.
// Table 2.2: Required data memory contents Required Content Comments
// Memory Location 0x00 Pointer to the start of the input data array
// Will be in the range Ox20-0x30 Must not be changed by your program Will be viewable in R1 after program completes execution and PC=OxOF
// 0x01 Number of digits in the account number to be validated
// Will be in the range 4-16 Must not be changed by your program Will be viewable in R2 after program completes execution and PC=OxOF
// 0x02 Last four digits of your ID Must be written by your program during execution *output Must be in BCD Will be viewable in R3 after program completes execution and PC=OxOF
// 0x03 Validity indicator Ox02 indicates a valid account number *output Ox08 indicates an invalid account number Determined and stored by your program Will be viewable in R4 after program completes execution and PC=OxOF
// 0x04 Checksum Determined and stored by your program (See Table 1.3) *output Will be viewable in R5 after program completes execution and PC=OxOF
// 0x05-0x1F Available for your use Note: It may be beneficial to use these available memory locations to store temporary values since there are only eight registers in the Register File
// 0x20-0x3F Input data array The account number digits will be stored in BCD and will be packed four per memory location. (See Table 2.1) Between one and four consecutive memory locations will be used to store the account number, depending on the length of the account number. Location and length of the account number specified by locations Ox00 and Ox01 Must not be changed by your program
// Data memory location Ox01 contains a value N, which indicates how many digits are in the account number to be validated. You can assume that N will be a value between 4 and 16. This value will be stored in memory location Ox01 prior to execution. You must write your code so that it can validate an account number of any length specified by the contents of data memory address Ox01. The input data will consist of the digits of the account number stored in BCD. Since BCD is a 4-bit code, four digits will be packed into each memory location. For example, if the input array begins in memory location Ox21, the six-digit account number 987654 would be stored as shown in Table 2.1.
// Table 2.1 Input data array example assuming a six-digit account number 987654 is stored starting at array location Ox21. "?" indicates that unknown data that is not part of the account number may be stored in adjacent bits.
// Data memory Contents address
// 0x21 1001 1000 0111 0110
// 0x22 0101 0100 ???? ????
// Your program must calculate the checksum and store it in data memory location Ox04.