: Write and assemble a program to add all the single digits of your ID number and save the result in WREG. Pick 7 random numbers (all single digit) if you do not want to use your ID number. Then use the MPLAB simulator to single-step the program and examine the registers.
answer:
The assembly program to add all the single digits of given number and to save the result in WREG is,
INCLUDE io.h //it includes the header file
cr EQU 0ah
lf EQU 0dh
data SEGMENT
num DB cr,lf ,'enter a number:', 0
sum_1 DB cr,lf ,'the sum is:', 0
ten DW?
temp DW 40 DUP (?)
data ENDS
code SEGMENT
ASSUME cs:code , ds:data
start:
mov ax , data
mov ds , ax // input the number
output num
inputs temp , 10
atoi temp // initialize
mov cx , 00h // stores the sum of digits
mov ten, 10 // iteration
cmp ax,0 //exit loop if the number =0
jz sum_1
cwd
idiv ten
addwf cx, ds // add the unit digits and result is stored in wreg since the result is 8 bit
jmp next
sum_1 :output sum_1 // we can also output the result if we want to do so
itoa temp,cx
output temp
quit : mov al , 00h
mov ah, 4ch
int 21h
code ENDS
END start // end of program
the above given program is a assembly language preogram to add all the digits in a number and store the result into the wreg.and i have also output the sum of digits
Execution :
during execution enter the number - 5002466113
the output will both be displayed and stored
a.) program to pick a random number
Randmno: Ds1
randm:mov a , rendmno
jnz randmno
cpl a
mov randmno , a
randmno : anl a, #10100100b
mov , c, p
mov a , randmno
rlc a
mov randmno , a
ret
simulation:
use simulator to single step the program and examine the file register values
by this method you can look the value of file registers at a specific step of the program
in mplab simulator , you follow tools > options >select embedded>select generic settings>debug startup>halt at main> click ok
you can see a green highted text in program . that is the place where the program stopped execution there you can click "step into" icon
now add " lata from sfs " to watchlist to view file registers
INCLUDE io.h //it includes the header file
cr EQU 0ah
lf EQU 0dh
data SEGMENT
num DB cr,lf ,'enter a number:', 0
sum_1 DB cr,lf ,'the sum is:', 0
ten DW?
temp DW 40 DUP (?)
data ENDS
code SEGMENT
ASSUME cs:code , ds:data
start:
mov ax , data
mov ds , ax // input the number
output num
inputs temp , 10
atoi temp // initialize
mov cx , 00h // stores the sum of digits
mov ten, 10 // iteration
cmp ax,0 //exit loop if the number =0
jz sum_1
cwd
idiv ten
addwf cx, ds // add the unit digits and result is stored in wreg since the result is 8 bit
jmp next
sum_1 :output sum_1 // we can also output the result if we want to do so
itoa temp,cx
output temp
quit : mov al , 00h
mov ah, 4ch
int 21h
code ENDS
END start // end of program
the above given program is a assembly language preogram to add all the digits in a number and store the result into the wreg.and i have also output the sum of digits
Execution :
during execution enter the number - 5002466113
the output will both be displayed and stored
a.) program to pick a random number
Randmno: Ds1
randm:mov a , rendmno
jnz randmno
cpl a
mov randmno , a
randmno : anl a, #10100100b
mov , c, p
mov a , randmno
rlc a
mov randmno , a
ret
simulation:
: Write and assemble a program to add all the single digits of your ID number...
Write and assemble a program to: a) Set SP = $9D, b) Put a different value in each of RAM locations $9D, $9C, $9B, $9A, $99, and $98, c) POP each stack location into registers R20 – R24. d) Use the simulator to single-step and examine the registers, the stack, and the stack pointer.
1- Write a program that creates a dictionary of the English words for all single digit numbers as follows: 1: 'one', 2: 'two', 3: 'three', etc. 2- Write a function called numConvert that receives the above dictionary and an integer number as parameters, and prints the English words for all the number's digits. For example, if the function receives 2311, it will print: two three one one 3- Test your program by adding a main function, which calls numConvert. 4-...
PYTHON 1- Write a program that creates a dictionary of the English words for all single digit numbers as follows: 1: 'one', 2: 'two', 3: 'three', etc. 2- Write a function called numConvert that receives the above dictionary and an integer number as parameters, and prints the English words for all the number's digits. For example, if the function receives 2311, it will print: two three one one 3- Test your program by adding a main function, which calls numConvert....
2. Write an application that inputs a 3-digits number from the user and checks if all digits are prime numbers. If all digits are prime your program should stop. Use do/while for reading the input and any loop format to test if the number is prime. When checking the prime numbers don't use an if to check numbers from 1 - 9; you need to find an algorithm to check if the number is prime or not. Enter a 3-digit...
Write java program to check that a (16-digit) credit card number is valid. A valid credit card number will yield a result divisible by 10 when you: Form the sum of all digits. Add to that sum every second digit, starting with the second digit from the right. Then add the number of digits in the second step that are greater than four. The result should be divisible by 10. For example, consider the number 4012 8888 8888 1881. The...
java Write an application that input a number from the user and checks if all digits are prime numbers using method prime. The number entered can be of any size. If all digits are prime your program should stop. Use do/while for reading the input and any loop format to test if the number is prime. When checking the prime numbers don’t use an if to check numbers from 1 – 9; you need to find an algorithm to check...
Program Set 2 10 points) Credit card number validation Program Credit card numbers follow certain patterns: It must have between 13 and 16 digits, and the number must start with: 4 for Visa cards 5 for MasterCard credit cards 37 for American Express cards 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or whether a credit card...
Please answer in Visual Studio 2019 c# format. Not
python. Thank you.
Q. Write a program that works as described in the following scenario: The user enters a credit card number. The program displays whether the credit card number is valid or invalid. Here are two sample runs: Enter a credit card number as a long integer: 4388576018410707 4388576018410707 is valid Enter a credit card number as a long integer: 4388576018402626 4388576018402626 is invalid To check the validity of the...
Write a machine language program to input two one-digit numbers ranging from 0 to 4 (using the character input instruction), add them, and then output the single digit sum (using the character output instruction). Execute your program in the PEP/8 simulator. Example Input: 43 (this is the numbers 4 and 3. Remember, this is two ASCII characters when inputted into your program) Output: 7 (ASCII character 55dec)
C++: Write a recursive function that does the following: Given a number, add all the digits and display the sum. Example: The sum of the number 5432 would be 14. PLEASE PAY ATTENTION TO THE FOLLOWING: Do not use the static modifier. No global variables. Your program should implement a non-tail recursive algorithm. In other words, it should do something as it moves towards the base case, the tail, and also do something as it comes back from...