banner



How To Subtract Number In Register Lc3

#1

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: 1
  • Joined: 31-July xv

Using LC3 assembly I need to subtract two single digit numbers.

Posted 31 July 2015 - 01:42 PM

Instructions
I am supposed to prompts the user to input two numeric characters ('0'
... '9') from the user using Trap x20 (GETC). Make sure to repeat the characters and store them into
different registers. The 2d number will be subtracted from the first, and the operation reported in
the console: <showtime number> ‐ <second number> = <deviation> .
Output to the console the operation being performed (e.yard. iv ‐ half dozen = ). Using the same registers, convert
the numeric characters into the actual numbers they stand for (east.g.convert 'two' into 2).
Perform the subtraction functioning, and determine the sign (+/‐) of the effect; if negative, determine the
magnitude of the result (i.e. accept two'southward complement).
(Ex) Program performs (4‐6) and stores the result, ‐2, in a register. Plan recognizes that result is
negative, converts ‐2 to two, and sets flag for minus sign.
Convert resulting number back to a printable character and print it, together with minus sign if
necessary.
(Ex) Plan converts 2 into '2', and stores information technology dorsum in aforementioned register. Programme outputs the two characters
‐two followed by newline. thus completing the subtraction operation output.

My estimate
I am not fully sure how I should begin
I think I'm supposed to start with TRAP x20 and then register it to something like R3 and then repeat for a second number for R4. And then I have to subtract I think with a combination of ADD and NOT

What I take and then far

.ORIG x3000 ; Program begins hither ;------------- ;Instructions ;------------- ;---------------------------------------------- ;outputs prompt ;---------------------------------------------- LEA R0, intro ; PUTS ; Invokes BIOS routine to output string ;------------------------------- ;INSERT CODE STARTING FROM Here ;-------------------------------- HALT ; Stop execution of program ;------ ;Data ;------ ; String to explain what to input intro .STRINGZ "ENTER two numbers (i.e '0'....'nine')\northward" NEWLINE .STRINGZ "\n" ; String that holds the newline grapheme ;--------------- ;END of Plan ;--------------- .END            

This post has been edited by macosxnerd101: 31 July 2015 - 03:05 PM
Reason for edit:: Added lawmaking tags and moved to Associates


Is This A Good Question/Topic? 0

  • +

#ii turboscrew User is offline

Reputation: 173

  • View blog
  • Posts: i,115
  • Joined: 03-April 12

Re: Using LC3 assembly I need to subtract ii single digit numbers.

Posted 18 Baronial 2015 - 02:42 AM

I don't know virtually the BIOS and its TRAPS, but virtually the remainder of the stuff: yep.

This mail service has been edited by turboscrew: eighteen August 2015 - 02:43 AM

#3 NeoTifa User is offline

Reputation: 4946

  • View blog
  • Posts: 20,285
  • Joined: 24-September 08

Re: Using LC3 assembly I need to subtract two single digit numbers.

Posted 19 August 2015 - 08:53 AM

I remember your guess is right. I haven't used LC3 in a minute, just that sounds virtually right.

#4 turboscrew User is offline

Reputation: 173

  • View blog
  • Posts: 1,115
  • Joined: 03-April 12

Re: Using LC3 associates I need to subtract two unmarried digit numbers.

Posted 31 August 2015 - 01:45 PM

Oops, didn't realize - Non is 1's complement.
You need to add 1 to make it 2'southward complement:
a - b = a + Non( b ) + 1

Yous read a character with trap x20 (character emerges in low byte of r0).
You echo it with trap x21 (with graphic symbol in low byte of r0)
The decimal digits are converted to binary subtracting '0' (0x30) from the ASCII-lawmaking, and vice versa. Multidigit numbers require a bit more.

It might be a good idea to write a pseudocode kickoff.

And recollect to decide which registers you employ for what and where, and stick to the plan (unless you need to rethink that). Otherwise the usage of registers get blurred, and ane ends up using wrong registers - like press address instead of value, or incrementing data instead of counter.

This post has been edited by turboscrew: 31 August 2015 - 01:45 PM

Source: https://www.dreamincode.net/forums/topic/379580-using-lc3-assembly-i-need-to-subtract-two-single-digit-numbers/

Posted by: jacksonthaintrack.blogspot.com

0 Response to "How To Subtract Number In Register Lc3"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel