so I was looking for how output works in lc3 but none of them were clear. all I know is that it has something to do with a trap function. so I just would like to know how to print a number to the console.
1
There are 1 best solutions below
Related Questions in ASSEMBLY
- Is it possible to use ES5 JavaScript with Angular 2 instead of TypeScript?
- Module '"angular2/angular2"' has no exported member 'For'
- import syntax in typescript creating another js file in visual studio
- Separate ts file for imports
- How to use an AngularJS 2 component multiple times in the same page?
- injectables not working in angular 2.0 latest build 26
- Does angular2 bootstrap have a way to dynamically target elements like it does in angular 1.x
- Import {} from location is not found in VS Code using TypeScript and Angular 2
- Angular 2/Typescript: require not found
- ng-switch in Angular2
Related Questions in LC3
- Is it possible to use ES5 JavaScript with Angular 2 instead of TypeScript?
- Module '"angular2/angular2"' has no exported member 'For'
- import syntax in typescript creating another js file in visual studio
- Separate ts file for imports
- How to use an AngularJS 2 component multiple times in the same page?
- injectables not working in angular 2.0 latest build 26
- Does angular2 bootstrap have a way to dynamically target elements like it does in angular 1.x
- Import {} from location is not found in VS Code using TypeScript and Angular 2
- Angular 2/Typescript: require not found
- ng-switch in Angular2
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
LC-3's output trap prints characters to the console — and that is all it can do. This is how computers with consoles actually work — character output only.
You can print anything you need using character output only: strings, spaces, newlines, tabs, numbers, etc...
If you want multiple digit numeric output, that consists of multiple characters that are individual digit characters. If you want formatted output, that requires characters for formatting — numbers and strings, interspersed with spaces, newlines as desired.
So, for numeric output you print as many characters as you need in order to print the digits for the number.
Conversion algorithms for number to string are often called
itoa
— for integer to ascii. They convert the number to digit characters either going left to right or right to left.A right to left approach computes value mod (%) 10 in order to extra one digit at a time, the does div (/) 10 and loops until nothing (zero) is left. The digits, however, come out backwards, so they have to be buffered in order to reverse them so they can come out forwards.
A left to right approach starts with the maximum power of 10 as a divisor (e.g. 10,000 for 16-bit numbers, smaller for smaller number ranges), and produces one digit at a time in that manner repeating with the remainder after the division for the next digit (using the next smaller power of ten).
Complicating things is that either approach requires mod and div, which are not available directly in LC-3, but both can be had at once by repetitive subtraction.
Hex output is somewhat simpler in that it does not require divide or mod by 10, but does require a fair amount of careful shifting (which LC-3 can only do one bit at a time, and to the left, by adding something to itself).